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?
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 Cherry64,505 pts.
All Answer Wiki Contributors: Denny Cherry64,505 pts.
If you live outside the United States, by submitting your email address you consent to having your personal data transferred to and processed in the United States.
Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.
Thank you very much for the help. You are very kind and helpful.
Tzach.
No problem. I’m happy to help.