SQL Server - Return SCHEMA for sysobjects

后端 未结 8 1464
旧巷少年郎
旧巷少年郎 2020-12-29 21:30

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

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-29 22:29

    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.

提交回复
热议问题