SQL Server - Return SCHEMA for sysobjects

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

    Just to repeat what's already been suggested here, here's what I've used, to get a list of Tables, Stored Procedures, Views and Functions in my database:

    SELECT schema_Name(schema_id)  as  SchemaName,
           [name],              --  Name of the Table, Stored Procedure or Function
           [type]               --  'V' for Views, 'U' for Table, 'P' for Stored Procedure, 'FN' for function
    FROM sys.objects 
    WHERE [type_desc] IN ( 'USER_TABLE', 'SQL_STORED_PROCEDURE', 'VIEW', 'SQL_SCALAR_FUNCTION')
    AND [name] NOT LIKE 'sp_%'
    AND [name] NOT LIKE 'fn_%'
    ORDER BY 3 DESC,        --  type first
            1 ASC,          --  then schema
            2 ASC           --  then function/table name
    

    ...and here's what our good friend Northwind would return...

提交回复
热议问题