Walkthrough: Put an Existing Database under Version Control

In this walkthrough, you learn how to put an existing database under source control, which consists of the following steps:

  • You create a database project.

  • You connect to an existing database.

  • You import the database schema from the existing database into the database project.

  • You review the results that are shown in the database project.

  • You put the database project and its contents under version control.

Prerequisites

This walkthrough assumes that you have installed a copy of the sample Northwind database on a database server that is running Microsoft SQL Server 2000. You must also have read/write permission to a version control system such as Microsoft Visual Studio 2005 Team Foundation Server or Microsoft Visual SourceSafe.

To create a database project

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

    The New Project dialog box appears.

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

  3. In the Templates list, click SQL Server 2000.

  4. In Name, type MyNorthwind, and accept the default values for Location and Solution Name.

  5. Select the Create directory for solution check box if it is not selected by default, and click OK.

    A solution is created that contains the MyNorthwind empty database project.

    Next you will start the Import Database Schema process, in which you specify a connection string to the source database.

To import the database schema from the existing Northwind database

  1. On the View menu, and click Schema View.

    Schema View appears if it was not already visible.

  2. Click MyNorthwind in Schema View.

  3. On the Project menu, click Import Database Schema.

    Note

    You can also right-click MyNorthwind and click Import Database Schema.

    The Import Database Schema into Database Project dialog box appears.

  4. In the Source Database list, click the connection that corresponds to your existing Northwind database. If you have not yet connected to that database, you must first create a connection to it. For more information, see How to: Create a Database Connection.

  5. Click Finish.

    As the schema is imported, project items that correspond to the objects that are in the database appear under the database project in Solution Explorer. Schema View shows the objects that are defined in the database project.

    Next you will explore the contents of the database project before you put it under version control.

To examine the results of importing the database schema

  1. In Schema View, expand the node for the database project, and then expand the Tables folder.

    The tables in the database project should match the tables in the database.

  2. Right-click the dbo.Employees table in the Tables subfolder, and click Open.

    The Transact-SQL editor appears and shows the definition for the dbo.Employees table.

  3. Expand the dbo.Employees object, and expand the Constraints folder within dbo.Employees.

  4. Right-click the CK_BirthDate constraint in Schema View, and click Open. You can also double-click the CK_BirthDate constraint.

    Another instance of the Transact-SQL editor appears and shows the definition for the CK_BirthDate constraint on the dbo.Employees table.

    In the final step, you put your solution, which contains the database project, under version control.

To put your solution under version control

  1. On the File menu, point to Source Control, and click Add Solution to Source Control.

  2. Click the version control project (Team Foundation Server refers to these as Team Projects) to which you want to add the solution by using procedures for your source control add-in. For more information, see either Working with Team Foundation Source Control or Performing Basic Visual SourceSafe Tasks.

    Your database project is now under version control.

See Also

Concepts

Terminology Overview of Team Edition for Database Professionals

Other Resources

Working with Database Projects in a Team Environment
Getting Started with Database Projects
Building and Deploying Version-controlled Databases
Editing Database Scripts and Objects with the Transact-SQL Editor