SYNTAX help on getting the STORED PROC Definition

  • Folks

    I know this can be done but I am not sure what system tables/views need to be accessed.

    I want to get the stored proc name and stored proc definition in the form of a SQL statement

    Select sp_name , sp_definition FROM ........

  • mw112009 (1/5/2016)


    Folks

    I know this can be done but I am not sure what system tables/views need to be accessed.

    I want to get the stored proc name and stored proc definition in the form of a SQL statement

    Select sp_name , sp_definition FROM ........

    For procedures, you can use this:

    SELECT p.name, m.definition

    FROM sys.procedures p

    JOIN sys.sql_modules m ON p.object_id = m.object_id

    For other objects, you can change the sys.procedures view to sys.objects.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Piling on, here is the short disco version

    😎

    SELECT OBJECT_DEFINITION(OBJECT_ID(N'[schema_name].[object_name]'));

  • USE AdventureWorks;

    GO

    SELECT definition

    FROM sys.sql_modules

    WHERE object_id = (OBJECT_ID(N'AdventureWorks.dbo.uspLogError'));

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply