Share via


How to: Specify Pre-Deployment or Post-Deployment Scripts

You might have one or more scripts that you want to run before or after the deployment of your database. Visual Studio Team System Database Edition provides a single pre-deployment script and a single post-deployment script in the database project. If your environment is relatively simple, you can add your script statements to these script files. If you have a more complex environment and need to run multiple scripts or one script multiple times, you might find it easier to use SQLCMD mode in the pre-deployment or post-deployment script to include your own deployment scripts.

To modify the pre-deployment script

  1. In Solution Explorer, expand your database project to display the Scripts folder.

  2. Expand the Scripts folder so that the Pre-deployment subfolder appears.

  3. Expand the Pre-deployment subfolder, and click the script.predeployment.sql file.

  4. On the View menu, click Open.

    The Transact-SQL (T-SQL) editor opens, displaying the contents of the script.predeployment.sql file. For information about SQLCMD mode and how to include your own scripts as part of the pre-deployment script, see Editing SQLCMD Scripts in the Transact-SQL Editor. Included scripts are executed in the order in which you include them, so you can control the running order of your pre-deployment scripts by including them in a specific order.

    Note

    You can also double-click the script.predeployment.sql file.

  5. When you have finished editing the script, open the File menu, and click Save script.predeployment.sql.

To modify the post-deployment script

  1. In Solution Explorer, expand your database project to display the Scripts folder.

  2. Expand the Scripts folder so that the Post-deployment subfolder appears.

  3. Expand the Post-deployment subfolder, and click the script.postdeployment.sql file.

  4. On the View menu, click Open.

    The Transact-SQL (T-SQL) editor opens, displaying the contents of the script.postdeployment.sql file. For information about SQLCMD mode and how to include your own scripts as part of the post-deployment script, see Editing SQLCMD Scripts in the Transact-SQL Editor. Included scripts are executed in the order in which you include them, so you can control the running order of your post-deployment scripts by including them in a specific order.

    Note

    You can also double-click the script.postdeployment.sql file.

  5. When you have finished editing the script, open the File menu, and click Save script.postdeployment.sql.

See Also

Tasks

How to: Enable SQLCMD mode in the Transact-SQL Editor

How to: Prepare Database Build Scripts

Concepts

Terminology Overview of Database Edition

Other Resources

An Overview of Database Scripts

Building and Deploying Version-controlled Database Schemas