Export (0) Print
Expand All

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 object to a specific schema from Solution Explorer

    When you create a database project, you can organize it by object type (the default) or by schema. If you organize it by schema, you can add database objects to a specific schema in Solution Explorer. For more information about how to use the New Database Project Wizard to specify the organization of your database project, see How to: Create Database and Server Projects. This approach works but is the least convenient. Your project must be organized in a specific manner, and you must add the objects in the correct place in Solution Explorer for them to added to the correct schema.

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, organizing the objects by schema.

    NoteNote:

    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 click New Item. For example, to create a table, right-click the Tables folder.

    The Add New Item dialog box appears.

    NoteNote:

    Instead of clicking New Item, you can also click the option for the type of item that you want to create, such as Table or View.

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

  6. In Templates, 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.

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.

    Caution noteCaution:

    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.

To add a database object to a specific schema from Solution Explorer

  1. In Solution Explorer, expand the node for your database project.

    Important noteImportant Note:

    If your database project is organized by object type, instead of by schema, you cannot use this procedure. You can use either of the other procedures in this topic.

  2. Expand the Schema Objects folder, and expand the Schemas subfolder.

    A folder appears in the Schemas folder for each schema that is defined in the database project.

  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 click New Item. For example, to create a table, right-click the Tables folder.

    The Add New Item dialog box appears.

    NoteNote:

    Instead of clicking New Item, you can also click the option for the type of item that you want to create, such as Table or View.

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

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

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

  8. Click Add.

    The object is created in the folder that you right-clicked, even if the object type does not match the folder name.

Community Additions

ADD
Show:
© 2014 Microsoft