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

后端 未结 9 512
予麋鹿
予麋鹿 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条回答
  •  梦毁少年i
    2021-01-30 20:06

    The other answers that recommend using the object explorer and scripting the stored procedure to a new query editor window and the other queries are solid options.

    I personally like using the below query to retrieve the stored procedure definition/code in a single row (I'm using Microsoft SQL Server 2014, but looks like this should work with SQL Server 2008 and up)

    SELECT definition 
    FROM sys.sql_modules 
    WHERE object_id = OBJECT_ID('yourSchemaName.yourStoredProcedureName')
    

    More info on sys.sql_modules:

    https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-sql-modules-transact-sql

提交回复
热议问题