Alerts and jobs can be quite complex and time consuming to set up and debug. Regular backups of the MSDB database?where the definitions for alerts and jobs are stored?will protect you against loss of these objects; however, it is also a good idea to script at least your most complex jobs. Scripting is also a good way to store versions of a job as it is modified. If the modification doesn't have the desired behavior, the script can be run to restore the previous version. Another use for scripts is to easily transfer jobs or alerts to another server. To generate a script for a job or alert, right-click it and select Generate SQL Script. Provide a name for the file and select the text format and whether the script should generate DROP commands (replace) for the object. A Preview button is also available so you can view the script, as shown in Figure 18.15.
Figure 18.15. Previewing SQL script generation.