Backup Programmability in SQL Server 2005
How can I backup the Programmability (functions, triggers stored procedures etc.) as part of a schedule job? Do I need to write code or can I use the wizard?

Software/Hardware used:
ASKED: February 20, 2008  3:11 PM
UPDATED: March 2, 2008  9:44 PM

Answer Wiki:
These are backed up when you backup the database itself. If you wanted to write something to script out the procedures, functions, triggers, etc and save them somewhere you would need to use the sp_helptext procedure within a cursor which gets the object names from the sys.procedures, sys.triggers, and sys.functions DMVs. <pre>declare @name as sysname declare cur CURSOR for SELECT name FROM sys.procedures open cur fetch next from cur into @name while @@FETCH_STATUS = 0 BEGIN exec sp_helptext @name print 'GO' fetch next from cur into @name END close cur deallocate cur</pre> The above code will print all the code on the screen. If you put this into a job step, and setup the advanced properties of the job step to log the output to a text file, you'll get all the stored procedure T/SQL into a single file. This can be replicated for triggers, functions, etc.
Last Wiki Answer Submitted:  February 20, 2008  10:22 pm  by  Denny Cherry   64,505 pts.
All Answer Wiki Contributors:  Denny Cherry   64,505 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.

 64,505 pts.

 

Thank you very much for the help. You are very kind and helpful.

Tzach.

 15 pts.

 

No problem. I’m happy to help.

 64,505 pts.