Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

How to: Add Management Scripts to a Database Project

In addition to deployment scripts, you can also add management scripts to a database project. You should add these types of scripts to the database project if they contain statements that might need to change over time as the database changes. By adding them to the database project and putting it under version control, you can track changes and revert to an earlier version if necessary. You can add an empty script and then edit it as needed, or you can add an existing script.

Adding New or Existing Scripts

To add an empty script to a database project

  1. In Solution Explorer, click the database project, or click the Scripts folder in the database project.

    NoteNote

    You can add scripts anywhere within your database project. The default database project has a Scripts folder, but you can add management scripts anywhere in the project structure.

  2. On the Project menu, click Add New Item.

    The Add New Item dialog box appears.

  3. In the Templates list, click the Script icon.

  4. In Name, type the name that you want to give the new script.

  5. Click Add.

    The script is added to your project, appears in Solution Explorer, and opens in the Transact-SQL (T-SQL) editor.

To add an existing script to a database project

  1. In Solution Explorer, click the database project, or click the Scripts folder in the database project.

    NoteNote

    You can add scripts anywhere within your database project. The default database project has a Scripts folder, but you can add management scripts anywhere in the project structure.

  2. On the Project menu, click Add Existing Item.

    The Add Existing Item dialog box appears.

  3. Browse to the script that you want to add to your project, and click its file name.

    You can also type the path and file name of the script in the File name field.

  4. Click Add.

    A copy of the script is added to your project and appears in Solution Explorer. The original file is not affected.

Database Projects under Version Control

If your database project is under version control, you must follow some additional steps. When you add a script to the database project, you must check out and update the .dbproj file. After you follow one of the previous procedures, you should check in the changes to your project.

To check in changes after you add a script to a version-controlled database project that uses Team Foundation Server

  1. On the File menu, point to Source Control, and click Check In. As an alternative, you can use the Pending Changes window. On the View menu, point to Other Windows, and click Pending Changes.

    Either the Check In dialog box or the Pending Changes window appears, depending on which approach you chose.

  2. In Comment, type a description of the changes you are checking in.

  3. Review the list of changed files, select the check boxes for those files that you want to check in to version control, and clear the check boxes for those files that you want to leave checked out.

  4. Click Check In either in the Check In dialog box or on the toolbar in the Pending Changes window.

    The files that you selected are checked into version control.

See Also

Show:
© 2015 Microsoft