SQL Server - Return SCHEMA for sysobjects

后端 未结 8 1466
旧巷少年郎
旧巷少年郎 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:12

    I would favor using the more focused "sys" views - sys.procedures instead of sys.objects. You'll need to join it with the sys.schemas view to get schema name and such.

    select
        p.name, 
        s.name 'Schema',
        p.type_desc, p.create_date, p.modify_date
    from
        sys.procedures p
    inner join
        sys.schemas s ON p.schema_id = s.schema_id
    

    I would start to get away from using "sysobjects" since Microsoft clearly states in Books Online that "sysobjects" is subject to removal in a future release:

    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. To find the equivalent system view or views, see Mapping SQL Server 2000 System Tables to SQL Server 2005 System Views. This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.

    Marc

提交回复
热议问题