Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server - Return SCHEMA for sysobjects

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'.

like image 240
Gerhard Weiss Avatar asked May 27 '09 18:05

Gerhard Weiss


People also ask

How do I find the SYS objects in SQL Server?

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.

What is SQL Sysobjects?

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.


1 Answers

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 
like image 66
devio Avatar answered Sep 22 '22 17:09

devio