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 Build DatabaseProject.

    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.

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 2005/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:

    Microsoft (R) Build Engine Version 2.0.50727.42

    [Microsoft .NET Framework, Version 2.0.50727.42]

    Copyright (C) Microsoft Corporation 2005. All rights reserved.

    Build started 10/17/2006 10:13:23 AM.

    __________________________________________________

    Project "ProjectDrive:\Documents and Settings\UserName\My Documents\Visual Studio 2005\Projects\SolutionName\DatabaseProject\DatabaseProject.dbproj" (build target(s)):

    Target SqlBuild:

    Building deployment script for DatabaseProject : EnableFullTextSearch, BlockIncrementalDeploymentIfDataLoss

    . DatabaseProject --> file:///ProjectDrive:/Documents%20and%20Settings/UserName/My%20Documents/Visual%20Studio%202005/Projects/SolutionName/DatabaseProject/sql/DatabaseProject.(local).DatabaseProject.sql

    Build succeeded.

    0 Warning(s)

    0 Error(s)

    Time Elapsed 00:00:05.95

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
How to: Configure Database Projects for Build and Deployment
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
Terminology Overview of Team Edition for Database Professionals

Other Resources

An Overview of Database Project Settings