Was: How to back up selected stored procedure using query
I would like to backup 10 out of 200 stores procedures over command line ( In SQL Server Management Studio). Is there an easy way to do it?
Right now I am using the Database->Tasks->Generate Scripts option, that takes me through a series of dialog where I choose the SP that I want to export. I would like to make this process easy, so I don't have to do it all over again.
Note: By Export I mean just print it on the screen so I can copy it and save it in a text file.
How about using INFORMATION_SCHEMA.Routines ?
DECLARE MY_CURSOR Cursor
FOR
SELECT r.Routine_Definition
FROM INFORMATION_SCHEMA.Routines r
OPEN MY_CURSOR
DECLARE @sproc VARCHAR(MAX)
FETCH NEXT FROM MY_CURSOR INTO @sproc
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF (@@FETCH_STATUS <> -2)
PRINT @sproc
FETCH NEXT FROM MY_CURSOR INTO @sproc
END
CLOSE MY_CURSOR
DEALLOCATE MY_CURSOR
GO
EDIT
It sounds like you might want something like this to include the LAST_ALTERED date and Definition in a result set.
SELECT
r.LAST_ALTERED,
r.ROUTINE_NAME,
r.Routine_Definition
FROM INFORMATION_SCHEMA.Routines r
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With