How to identify system objects when viewing list of SQL Server database objects?

后端 未结 2 1256
误落风尘
误落风尘 2021-01-22 03:04

I\'m trying to list all the stored procedures from all the databases on my server, and I can\'t seem to filter out system objects reliably. I was using:

SELECT *         


        
相关标签:
2条回答
  • 2021-01-22 03:44

    SQL Server 2005 and higher

    SELECT
      SCHEMA_NAME(obj.schema_id) AS schema_name,
      obj.name AS proc_name
    FROM
      sys.procedures obj WITH(NOLOCK)
    ORDER BY
      schema_name,
      proc_name
    

    SQL Server 2000

    SELECT
      USER_NAME(obj.uid) AS user_name,
      obj.name AS proc_name,
    FROM
      sysobjects obj WITH(NOLOCK)
    WHERE
      (obj.status & 0x80000000) = 0
      AND RTRIM(obj.xtype) IN ('P', 'RF')
    ORDER BY
      user_name,
      proc_name
    
    0 讨论(0)
  • 2021-01-22 03:58

    This works on my SQL Server 2008 R2 install. I don't see much at all except for user databases

    SELECT 
        *
    FROM
       sys.objects
    WHERE
       OBJECTPROPERTY(object_id, 'IsMSShipped') = 0
    

    You can change sys.objects to say, sys.tables and it still works, or use the "type" column to filter. Or use OBJECTPROPERTY(object_id, 'IsProcedure') etc.

    Note: it's sys.objects in SQL Server 2005+

    Note 2: OBJECTPROPERTY will work for SQL Server 2000 too:

    SELECT 
        *
    FROM
       sysobjects
    WHERE
       OBJECTPROPERTY(id, 'IsMSShipped') = 0
    
    0 讨论(0)
提交回复
热议问题