Share via


How to: Prepare Database Build Scripts

After you change the database project, you must prepare the build script to either create or update the target. You specify a new or existing database as the target by configuring build settings in the project properties. After you configure those settings, you can build the database project, which assembles any pre-deployment and post-deployment scripts together with the object definitions from the database project. After you prepare the database build script, you can deploy it to the target's database server.

To prepare a database build script in Visual Studio

  1. In Solution Explorer, click the node for the database project for which you want to prepare a build script.

  2. On the Build menu, click BuildDatabaseProject.

    The object definition scripts and pre-deployment and post-deployment scripts are assembled.

To prepare a database build script from the command line

  1. Open the Command Prompt window, and browse to your project directory.

    By default, projects are created in My Documents/Visual Studio 2008/Projects.

  2. At the command prompt, type the following command line to generate a build script where DatabaseProject is the name of your project:

    MSBuild /t:Build Path\DatabaseProject.dbproj

    Note

    MSBuild.exe must be on the path that your PATH environment variable specifies. In addition, the name of the target database must be set either in the database project or as part of the command line. If you are generating an update script, you must also specify the TargetConnectionString. For more information about command line syntax for generating build scripts, see An Overview of Database Build and Deployment.

    The object definition scripts and pre-deployment and post-deployment scripts are assembled. If you are preparing an update script, the target connection that you specified in the build settings determines what updates you must have in order to synchronize the target with the database project. Results such as the following appear:

    ------ Build started: Project: ProjectName, Configuration: Debug Any CPU ------

    Verifying project state.

    Finished verifying project state.

    ProjectName -> ProjectDrive:\Documents and Settings\UserName\My Documents\Visual Studio 2008\Projects\SolutionName\ProjectName\sql\ProjectName.dbschema

    ========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

Security

You can prepare a build script to create a database without having permissions on a target database or server because you do not have to access the database to build the database project for a new deployment. To prepare an update script, you must have permission to access the server, the database, and the database objects in the target.

See Also

Tasks

How to: Deploy Changes to New or Existing Databases

Walkthrough: Create and Deploy a New Version-Controlled Database

Walkthrough: Deploy Changes to an Existing Version-Controlled Database

Concepts

An Overview of Database Build and Deployment

An Overview of Database Project Settings

Terminology Overview of Database Edition

Build and Deploy Databases to an Isolated Development Environment

Build and Deploy Databases to a Staging or Production Environment