Liath
Liath

Reputation: 10191

How to script a stored procedure from TSQL

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

Answers (3)

Upendra Chaudhari
Upendra Chaudhari

Reputation: 6543

Try using sp_helptext command :

sp_helptext 'yourprocname'

or using object_definition :

SELECT OBJECT_DEFINITION(OBJECT_ID('yourprocname')) 

Upvotes: 5

Widor
Widor

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

Martin Smith
Martin Smith

Reputation: 452998

SELECT OBJECT_DEFINITION(OBJECT_ID('your_schema.your_procname'))

or

EXEC sp_helptext 'your_schema.your_procname'

Upvotes: 3

Related Questions