Saving a Change Script

Visual Database Tools

Visual Database Tools

Saving a Change Script

You can save an SQL change script if you do not have security permissions to alter a database or if you are not ready to update the database (for example, if you have 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, the Microsoft® SQL Server™ command-line utility osql).

To save a change script

  1. Right-click inside the database diagram, and then click 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.

  3. 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 each subsequent 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 could not 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.

See Also

Database Changes Detected Dialog Box | Saving Selected Tables