Reputation: 10191
I know there's a way to do this as I've seen it done - I just can't remember how.
I want to run a SQL command which will return the script to create the stored procedure as a result.
How can I do this?
Upvotes: 5
Views: 11874
Reputation: 6543
Try using sp_helptext command :
sp_helptext 'yourprocname'
or using object_definition :
SELECT OBJECT_DEFINITION(OBJECT_ID('yourprocname'))
Upvotes: 5
Reputation: 13275
In SQL Server Management Studio, right-click the proc in the Object Explorer window and choose Script Stored Procedure as ...then choose the operation (Create, Drop, etc.) you want to script.
Upvotes: 0
Reputation: 452998
SELECT OBJECT_DEFINITION(OBJECT_ID('your_schema.your_procname'))
or
EXEC sp_helptext 'your_schema.your_procname'
Upvotes: 3