I know we can do this by going Tasks > Generate Scripts > Stored Procedure.
Is there a way to do it using sqlcmd? I'm planning to write a batch file to automate it.
I know we can do this by going Tasks > Generate Scripts > Stored Procedure.
Is there a way to do it using sqlcmd? I'm planning to write a batch file to automate it.
You could combine the system table sys.procedures and the function object_definition.
-- Return the name and definition of first three SPs in the current db.
SELECT TOP 3
Name,
OBJECT_DEFINITION(object_id) AS SQLStatement
FROM
sys.procedures
ORDER BY
Name
;
Word of warning; If a procedure is renamed using sp_rename, the old definition is returned. This is a closed bug on connect.