Saving a Change Script

See Also

You can save an SQL change script if you don’t have security permissions to alter a database or if you’re not ready to update the database (for example, if you've made changes to the database diagram that conflict with changes made by other users). An SQL change script provides a record of your changes that can be applied to the database at a later time using a database tool (for example, Microsoft® SQL Server’s™ isql command-line utility).

To save a change script

  1. From the File menu or the Database Designer toolbar, choose Save Change Script. This command is available whenever you have unsaved database changes in your diagram.

  2. In the Save Change Script dialog box, choose Yes.

Note   If the option to automatically generate a change script is selected, a change script is generated whenever you save your database diagram or any changed database object in the diagram. This is helpful if you need to track the changes you have made to the database.

  1. A message box displays the file name of the saved change script. Choose OK.

Each time you save a change script, a new text file named DbDgmN.sql (where N equals 1 for the first change script you generate and N+1 for the next change script) is created and saved in the current working directory.

The change script file lists any changed tables and how they were changed (using the DROP TABLE, ALTER TABLE, or CREATE TABLE SQL statements). The change script file also contains any error handling code that is required to clean up temporary tables or to rollback transactions that were part of unsuccessful changes (changes that couldn't be saved). In addition, the change script file contains code to make the script run successfully against the database and code (Print statements) that describe what the script is doing when it runs.

Any error messages that occurred while the changes were saved are stored in a log file, with the same name as the script file, except with a .log extension. You can also view messages showing which tables were successfully and unsuccessfully saved in the Log Viewer.