How to view the stored procedure code in SQL Server Management Studio

后端 未结 9 528
予麋鹿
予麋鹿 2021-01-30 19:35

I am new to SQL Server. I am logged into my database through SQL Server Management Studio.

I have a list of stored procedures. How do I view the stored procedure code?

9条回答
  •  天涯浪人
    2021-01-30 20:04

    You can view all the objects code stored in the database with this query:

        USE [test] --Database Name
    SELECT
        sch.name+'.'+ob.name AS       [Object], 
        ob.create_date, 
        ob.modify_date, 
        ob.type_desc, 
        mod.definition
    FROM 
         sys.objects AS ob
         LEFT JOIN sys.schemas AS sch ON
                sch.schema_id = ob.schema_id
         LEFT JOIN sys.sql_modules AS mod ON
                mod.object_id = ob.object_id
    WHERE mod.definition IS NOT NULL --Selects only objects with the definition (code)
    

提交回复
热议问题