Search code examples
sqlsql-server-2005t-sqlsqlpubwiz

Automatically create scripts for all SQL Server Jobs


Currently I'm trying to automatically generate a create script for all my SQL jobs of a MS SQL2005 Server.

  • One method I found was done manually http://msdn.microsoft.com/en-us/library/ms191450.aspx

  • A second method I found could be done automatically but I don't have direct access to the SQL server.

    Broken link removed: relatedterms.com/thread/1916663/Can%20I%20script%20out%20SQL%20Server%20jobs%20programmatically

Does anyone know a good TSQL statement or a simple program for this?


Solution

  • After some further investigation I found a good script that did the job Generate-Scripts-for-SQL-Server-Objects

    The code below is what I needed:

    DECLARE @object int
    exec sp_OACreate 'SQLDMO.SQLServer', @object OUT
    exec sp_OASetProperty @object, 'LoginSecure', TRUE
    exec sp_OAMethod @object,'Connect(sqltest)'
    exec sp_OAMethod @object, 'Jobserver.Jobs().Script()'
    exec sp_OADestroy @object
    

    Thanks for the help anyway