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开发者_StackOverflow中文版 to run a SQL command which will return the script to create the stored procedure as a result.
How can I do this?
Try using sp_helptext command :
sp_helptext 'yourprocname'
or using object_definition :
SELECT OBJECT_DEFINITION(OBJECT_ID('yourprocname'))
SELECT OBJECT_DEFINITION(OBJECT_ID('your_schema.your_procname'))
or
EXEC sp_helptext 'your_schema.your_procname'
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.
精彩评论