How to I get the SCHEMA when doing a select on sysobjects?
I am modifing a stored procedure called SearchObjectsForText which returns only the Name but I would also like to include the SCHEMA.
Right now it is doing something similar to this:
SELECT DISTINCT name FROM sysobjects
I would like to know what tables need to be joined to return the SCHEME for each 'name'.
Navigate to View-> Object Explorer Details in SSMS. You can use a keyboard shortcut F7 to open it. It opens the following screen and shows the various folders – Databases, Security, Server objects, Replication, PolyBase, Always on High Availability.
Contains one row for each object that is created within a database, such as a constraint, default, log, rule, and stored procedure. This SQL Server 2000 system table is included as a view for backward compatibility. We recommend that you use the current SQL Server system views instead.
If you mean SQL Server 2005 or higher, use sys.objects instead of sysobjects:
SELECT sys.objects.name, sys.schemas.name AS schema_name FROM sys.objects INNER JOIN sys.schemas ON sys.objects.schema_id = sys.schemas.schema_id
2005 introduced schemas. up to 2000, users equaled schemas. The same query for SQL Server 2000:
SELECT sysusers.name AS OwnerName, sysobjects.name FROM sysobjects INNER JOIN sysusers ON sysobjects.uid = sysusers.uid
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With