Share via


How to: Create Database Projects

A database project is the offline representation of a database and the mechanism by which you manage changes to the database. To create a version-controlled database project from an existing database, you create a database project, import the schema information from the database, and then check the project and its files into version control.

Note

An error message might appear when you create a database project if you do not have the appropriate permissions in the local instance of Microsoft SQL Server that is used for design-time validation. If you are not logged on with administrative credentials on your computer, you might have to ask your administrator to grant you permissions to create databases in SQL Server. For more information about how to specify the local instance to use for design-time validation, see How to: Specify the Local Instance of SQL Server to use for Design-time Validation.

You can create the project from an existing database by using the New Database Project Wizard or by performing the equivalent steps manually.

To create a database project from an existing database using the New Database Project Wizard

  1. On the File menu, point to New, and click Project.

    The New Project dialog box appears.

  2. In Project types, expand the Database Projects node, and click Microsoft SQL Server.

    The Templates list displays the available database project templates.

  3. If you want to create a Microsoft SQL Server 2005 database, click SQL Server 2005 Wizard. If you instead want to create a SQL Server 2000 database, click SQL Server 2000 Wizard.

  4. In Name, type the name that you want to give the database project.

    This name can be the same as that of the database that you want to manage, or you can give the project and the database different names.

  5. In Location, type or click the path to where you want to create the database project.

  6. In Solution, click Create new Solution if you want to create a solution for the database project. If you want to add the database project to the existing solution, click Add to Solution.

  7. If you want to create a directory to contain the solution, select the Create directory for solution check box.

  8. In Solution Name, type the name that you want to give the solution.

    By default, this name is the same as the project name.

  9. If you want to add the new solution and project to version control immediately, make sure that the Add to Source Control check box is selected. Clear the check box if you will add the solution and project to version control later, or if you do not plan to use version control with this solution.

  10. Click OK.

    The New Project Database Wizard appears. Next you use the wizard to configure your project and select the database from which you want to import the database schema.

To configure your project and import a database schema

  1. Click Next after you read the Welcome page.

  2. If you want the files in your project to be organized by object type (for example, tables together or views together) as the primary sort criteria, click Organize my project by Object Type. If you want the files in your project organized first by schema first and then by object type, click Organize my project by Schema.

    Important

    You cannot change the default organization after the project is created. You can manually move files within Solution Explorer, but they will initially be added based on the organization that you specify in the wizard. If you expect to have multiple schemas in your project, you might want to organize your project by schema, instead of by object type. You can change the organization within Schema View by right-clicking the project, pointing to Change View, and clicking Object Type or Schema to group by object type or by schema, respectively.

  3. Specify the schemas for the two additional fields, and then click Next.

  4. On the Set Database Options page, you can configure the options for the database project. For more information, see An Overview of the New Database Project Wizard.

    Note

    You can change these options after the project has been created. For more information, see How to: Configure Database Projects for Build and Deployment.

  5. Click Next.

  6. On the Import Database Schema page, if you do not want to import a database schema, click Next, and go to step 11.

  7. If you want to import an existing database schema, select the Import existing schema check box.

    Note

    When you import a database schema, extended properties in the source database are also imported. Extended properties on an object are defined in the same file that contains the object definition. For example, extended properties on a table MyTable will result in sp_addextendedproperty statements being added to the MyTable.table.sql file. This action affects sp_addextendedproperty, sp_settriggerorder, sp_tableoption, and sp_indexoption statements.

  8. In Source database connection, click the connection that corresponds to the server and database from which you want to import the database schema. If the connection does not already exist, click New Connection to create it. If you do not specify a connection, the database project is created, but no schema is imported.

    Note

    You can import a database schema later, if the database project does not already contain database objects. For more information, see How to: Import a Database Schema.

  9. Configure the import options if necessary. For more information, see An Overview of the New Database Project Wizard.

  10. Click Next.

  11. On the Configure Build/Deploy page, you can specify your initial user settings that control how the database project will be built and deployed. For more information, see An Overview of the New Database Project Wizard.

    Note

    You can change these options after the project has been created. For more information, see How to: Configure Database Projects for Build and Deployment.

  12. Click Finish to create the database project and import the database schema if you specified one.

    The database project is ready for you to use. You can check it into version control if you are working in a team environment.

See Also

Tasks

How to: Create Empty Database Projects
Walkthrough: Put an Existing Database under Version Control

Concepts

Terminology Overview of Team Edition for Database Professionals

Other Resources

Getting Started with Database Projects
Working with Database Projects in a Team Environment