How to: Add Database Objects to a Specific Schema

If your database project contains more than one schema, you might want to specify the schema to which database objects are added. You can use the following approaches:

  • Add the object to a specific schema from Schema View

    You can change how database objects are grouped within Schema View. If you group the objects by schema, you can add objects to a specific schema. You can use this approach whether you have organized your database project by schema or by object type. This approach is recommended.

  • Change the default schema before you add the object

    You can change the default schema before you add a database object. All database objects that you add after you change the default schema are added to that schema. This approach works best if you work primarily in a single schema at a time. This approach is inefficient if you must add objects to several schemas because you must keep changing the default schema. The advantage of this approach is that you do not have to add the object to the correct schema in Schema View. You can add the object anywhere, and it will be added in the correct schema.

Add the Database Object to a Specific Schema from Schema View

To add a database object to a specific schema from Schema View

  1. If Schema View shows your database objects organized by object type, click Show objects by schema in the Schema View toolbar.

    Schema View collapses any expanded items and organizes the objects by schema.

    Note

    After you have completed this procedure, you can click Show objects by type to display the objects, organized by type.

  2. In Schema View, expand the node for your database project, and expand the Schemas subfolder.

  3. Expand the folder for the schema to which you want to add the database object.

  4. Right-click the folder for the type of object that you want to create, point to Add, and then click the item that corresponds to the type of item that you want to add. For example, to create a table, right-click the Tables folder point to Add, and then click Table.

    The Add New Item dialog box appears.

  5. In Installed Templates, click the category for the type of object that you want to add.

  6. In the details pane, click the type of object that you want to add.

  7. In Name, type the name that you want to give the new database object.

  8. Click Add.

    The object is created and the file that contains the object definition is created in the appropriate folder for that type of object in your database project.

Change the Default Schema Before You Add a Database Object

To change the default schema

  1. In Solution Explorer, click the database project for which you want to change the default schema.

  2. Open the Project menu, and click ProjectName Properties.

    The project's properties window appears.

  3. Click the Project Settings tab.

  4. In Default Schema, type the schema to which you want objects to be added.

    Warning

    No validation is performed on the name of the schema that you specify. If you mistype your schema name, the objects will be created in the misspelled schema, and you will have to manually correct each object.

  5. Open the File menu, and click Save All.

    Now you can create database objects and they will be added to the schema that you specified in step 4. For more information about how to create a database object, see How to: Create a Database Object.

See Also

Concepts

Build and Deploy Databases to an Isolated Development Environment

Creating and Modify Database and Server Objects