October 31, 2014 at 2:50 pm
Hi, is there a way to backup all stored procedures in a database?
October 31, 2014 at 3:12 pm
if you just want the stored procedures and no data, probably your best bet is scripting:
From within Management Studio, in the Object Explorer, expand your database, expand the Programmability folder, and select "Stored Procedures" folder. Then press the F7 key to open the Object Explorer Details page. From there, you can select all or as many stored procs as you want, right click, then select "Script Stored Procedure as > Create To > File..."
October 31, 2014 at 7:44 pm
gary1 (10/31/2014)
Hi, is there a way to backup all stored procedures in a database?
Yes... have a look at the sys.sql_modules view. There's more than just Stored procedures there, as well.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 2, 2014 at 12:43 pm
In terms of a "backup" as defined by SQL Server backups, no.
But, as has already been pointed out, there are a number of mechanisms for scripting out the procedures. Might I add, it's a good idea to also then take those scripts and put them into source control. In fact, all your database objects should go into source control.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
November 2, 2014 at 12:57 pm
Chipping in my 2 cents, using a version / source control is good where it is applicable or possible but when it isn't, a combination of bcp and a simple query might do the job, here is an example of such a query
😎
SELECT
DB_NAME()
,OBJECT_SCHEMA_NAME(ASM.object_id) AS OBJ_SCHEMA
,OBJECT_NAME(ASM.object_id) AS OBJ_NAME
,ASM.definition AS OBJ_DEFINITION
FROM sys.all_sql_modules ASM
WHERE OBJECTPROPERTY(ASM.object_id,'IsProcedure') = 1
AND ASM.object_id > 0;
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply