You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Jobs are stored in the msdb database, but inside tables, not as code explicitly. I run this snippet to get their code, but wonder if there's something better (and not doing so by hand in SSMS, one by one)
SELECT [type] = 'JOB', [object] = J.name + ' - Step ' + convert(varchar,S.step_id) + ': ' + S.step_name, code = S.command
FROM [msdb].[dbo].[sysjobsteps] S
INNER JOIN [msdb].[dbo].[sysjobs] J
ON S.job_id = J.job_id
WHERE database_name = DB_NAME()
The text was updated successfully, but these errors were encountered:
here's a snippit from a larger Powershell process I have to script off jobs to disk...assumes $ServerName and $OutputFolder are set....dumps it all to one file...you could pipe each occurrence to its own file as well:
#Create a new SMO instance for this $ServerName
$srv = New-Object "Microsoft.SqlServer.Management.Smo.Server" $ServerName
#Script out each SQL Server Agent Job for the server to a file with no changes as a baseline
$srv.JobServer.Jobs | foreach {$_.Script() + "GO`r`n"} | out-file "$OutputFolder\jobs$(get-date -f yyyyMMdd_HHmmss).sql"
You could also use something like BCP to copy data in and out of job fields, I dont really think schemazen would want to go to separate databases and script out objects outside of the target.
Jobs are stored in the msdb database, but inside tables, not as code explicitly. I run this snippet to get their code, but wonder if there's something better (and not doing so by hand in SSMS, one by one)
The text was updated successfully, but these errors were encountered: