Query to list all stored procedures

后端 未结 23 1280
暖寄归人
暖寄归人 2020-11-28 17:18

What query can return the names of all the stored procedures in a SQL Server database

If the query could exclude system stored procedures, that would be even more he

相关标签:
23条回答
  • 2020-11-28 18:08

    This will give just the names of the stored procedures.

    select specific_name
    from information_schema.routines
    where routine_type = 'PROCEDURE';
    
    0 讨论(0)
  • 2020-11-28 18:08

    This is gonna show all the stored procedures and the code:

    select sch.name As [Schema], obj.name AS [Stored Procedure], code.definition AS [Code] from sys.objects as obj
        join sys.sql_modules as code on code.object_id = obj.object_id
        join sys.schemas as sch on sch.schema_id = obj.schema_id
        where obj.type = 'P'
    
    0 讨论(0)
  • 2020-11-28 18:09

    Unfortunately INFORMATION_SCHEMA doesn't contain info about the system procs.

    SELECT *
      FROM sys.objects
     WHERE objectproperty(object_id, N'IsMSShipped') = 0
       AND objectproperty(object_id, N'IsProcedure') = 1
    
    0 讨论(0)
  • 2020-11-28 18:10

    This will returned all sp name

    Select * 
    FROM sys.procedures where [type] = 'P' 
         AND is_ms_shipped = 0 
         AND [name] not like 'sp[_]%diagram%'
    
    0 讨论(0)
  • 2020-11-28 18:12
    select * from DatabaseName.INFORMATION_SCHEMA.ROUTINES where routine_type = 'PROCEDURE'
    
    select * from DatabaseName.INFORMATION_SCHEMA.ROUTINES where routine_type ='procedure' and left(ROUTINE_NAME,3) not in('sp_', 'xp_', 'ms_')
    
    
       SELECT name, type   FROM dbo.sysobjects
     WHERE (type = 'P')
    
    0 讨论(0)
  • 2020-11-28 18:13

    As Mike stated, the best way is to use information_schema. As long as you're not in the master database, system stored procedures won't be returned.

    SELECT * 
      FROM DatabaseName.INFORMATION_SCHEMA.ROUTINES
     WHERE ROUTINE_TYPE = 'PROCEDURE'
    

    If for some reason you had non-system stored procedures in the master database, you could use the query (this will filter out MOST system stored procedures):

    SELECT * 
      FROM [master].INFORMATION_SCHEMA.ROUTINES
     WHERE ROUTINE_TYPE = 'PROCEDURE' 
       AND LEFT(ROUTINE_NAME, 3) NOT IN ('sp_', 'xp_', 'ms_')
    
    0 讨论(0)
提交回复
热议问题