I have to download all stored procedures from a specific database.
There are around 130 stored procedures, and I can do it manually like by doing save as a file each one.
But is there any automatic option to download all ?
1) Open SQL Server Management Studio 2) Select your database in the Object Explorer 3) Right click > Tasks > Generate Scripts
4) Select only stored procedures to be scripted out
5) Following the wizard through the steps; on the next screen, pick option Single file per object
and define a directory where to put those files:
With those options, you get one file per stored procedure, stored in the directory of your choice.
You can do this in management studio - Right click the database you want and select tasks -> Generate scripts -> go through the wizard. You can then specify just stored procedures etc.
You can also use a script like this:
SET NOCOUNT ON
DECLARE @Test TABLE (Id INT IDENTITY(1,1), Code VARCHAR(MAX))
INSERT INTO @Test (Code)
SELECT 'IF object_ID(N''[' + schema_name(schema_id) + '].[' + Name + ']'') IS NOT NULL
DROP PROCEDURE ['+ schema_name(schema_id) +' ].[' + Name + ']' + CHAR(13) + CHAR(10) + 'GO' + CHAR(13) +CHAR(10) +
OBJECT_DEFINITION(OBJECT_ID) + CHAR(13) +CHAR(10) + 'GO' + CHAR(13) + CHAR(10)
FROM sys.procedures
WHERE is_ms_shipped = 0
DECLARE @lnCurrent INT, @lnMax INT
DECLARE @LongName VARCHAR(MAX)
SELECT @lnMax = MAX(Id) FROM @Test
SET @lnCurrent = 1
WHILE @lnCurrent <= @lnMax
BEGIN
SELECT @LongName = Code FROM @Test WHERE Id = @lnCurrent
WHILE @LongName <> ''
BEGIN
PRINT LEFT(@LongName,8000)
SET @LongName = SUBSTRING(@LongName, 8001, LEN(@LongName))
END
SET @lnCurrent = @lnCurrent + 1
END
You can also shift+click to select all the stored procedures and you can then right-click and script them to a file.
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