Share via


How to: Add Existing Items to a Database Project

You can add existing items to a database project just as you can for other project types, and the files for those items appear in Solution Explorer. In addition, you can configure items so they are treated as database objects and appear in both Solution Explorer and Schema View. You can also use the same property to designate your pre-deployment or post-deployment scripts.

To add a .sql file that contains a database object definition to the database project

  1. Click the node in Solution Explorer to which you want to add the file. For example, to add a file that contains a table definition, click the Tables node that is a child of the Schema Objects node in the database project.

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

    The Add Existing Item dialog box appears.

  3. In File name, type the path and file name of the file that you want to add to the database project. You can also browse to the file.

  4. Click Add.

    The file is added to the database project, appearing as a child of the node to which you added it. For example, if you added the file to the Tables node, the file appears as a child of that node.

  5. In Solution Explorer, click the newly added file.

  6. On the View menu, click Properties Window.

    The Properties window appears if it was not already displayed.

  7. Double-click the Build Action property, and type Build.

    By setting the Build Action property to Build, you indicate that the file contains the definition for a database object and should be parsed and validated. The file contents are parsed, and if the file contains valid SQL, the object that the file represents appears in Schema View. If one or more errors are found, they appear in the Error List window, and the object might not appear in Schema View.

    Note

    If Schema View is not showing, open the View menu, and click Schema View.

To add an existing script to the database project

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

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

    The Add Existing Item dialog box appears.

  3. In File name, type the path and file name of the file that you want to add to the database project. You can also browse to the file.

  4. Click Add.

    The file will be added to the database project, appearing as a child of the Scripts node.

  5. If you want the added script to be used as the pre-deployment or post-deployment script, click the newly added file. In the Properties window, double-click the Build Action property, and type PreDeploy or PostDeploy.

    Note

    You can have only a single pre-deployment script and a single post-deployment script for each database project. You can include additional files in your pre-deployment or post-deployment script. For more information about deployment scripts, see How to: Specify Pre-Deployment or Post-Deployment Scripts.

To add an existing data generation plan to the database project

  1. In Solution Explorer, click the Data Generation Plans folder in the database project.

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

    The Add Existing Item dialog box appears.

  3. In File name, type the path and file name of the file that you want to add to the database project. You can also browse to the file.

  4. Click Add.

    The file is added to the database project, appearing as a child of the Data Generation Plans node.

To add an existing miscellaneous file to the database project

  1. In Solution Explorer, click the node to which you want to add the miscellaneous file. For example, to add a file to the database project, click the database project node.

    Note

    You can add a folder to the database project to contain these miscellaneous files. To add a folder, click the database project, open the Project menu, and click New Folder.

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

    The Add Existing Item dialog box appears.

  3. In File name, type the path and file name of the file that you want to add to your database project. You can also browse to the file.

  4. Click Add.

    The file is added to your database project, appearing as a child of the node that you clicked in step 1.

See Also

Tasks

How to: Build a Database Project to Generate a Compiled Schema (.dbschema) File

How to: Exclude Files from a Database Project

Concepts

An Overview of Database and Server Projects

Creating and Modify Database and Server Objects