Where does SQL Server store the stored procedure code?

前端 未结 7 1209
情书的邮戳
情书的邮戳 2020-12-25 13:11

I once needed the lines of the stored procedures to be able to trace whether I have a reference to some function, procedure or table, or sometimes to try to find something i

7条回答
  •  礼貌的吻别
    2020-12-25 13:26

    Use sys.sql_modules because definition is nvarchar(max) because it will not truncate long code.

    In INFORMATION_SCHEMA.ROUTINES the ROUTINE_DEFINITION column is only nvarchar(4000) so if you try view the text of a long procedure and you will see that it is truncated.

    Use this to search for text in any procedure, view, function:

    SELECT DISTINCT
        o.name AS Object_Name,o.type_desc
        FROM sys.sql_modules        m 
            INNER JOIN sys.objects  o ON m.object_id=o.object_id
        WHERE m.definition Like '%'+@Search+'%'
        ORDER BY 2,1
    

    use this to view the text of a given procedure, view, function:

    select * from sys.sql_modules where object_id=object_id('YourProcedure')
    

提交回复
热议问题