SQL Server - Return SCHEMA for sysobjects

On Sql Server 2005 (and above) you can use the sys.objects view:

select 
  name                    as  ObjectName,     
  schema_Name(schema_id)  as  SchemaName
from 
  sys.objects

In Sql Server 2000 (and below), "schema" had a different conceptual meaning. Note from MSDN:

In earlier releases of SQL Server, databases could contain an entity called a "schema", but that entity was effectively a database user. SQL Server 2005 is the first release of SQL Server in which a schema is both a container and a namespace.


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