How to: Move a Database Object to a Different Schema

You can move a database object from one schema to another by using database refactoring in Schema View. You can then preview these changes before you apply them to your database project. You must then deploy the changes to update a target database. The refactoring log records all refactoring operations and helps preserve your intent when you deploy the changes. For more information, see Move a Database Object to a Different Schema.

To move a database object to a different schema

  1. In Schema View, right-click the object that you want to move, point to Refactor, and then click Move to Schema.

    The Move to Schema dialog box appears.

    Note

    You cannot refactor objects from a code window or from Solution Explorer.

  2. In the New Schema list, click the name of the schema into which you want to move the object.

  3. (Optional) Select the Preview changes check box.

    Note

    To update references in unit tests and scripts, you must select this check box. When the Preview Changes dialog box appears, you must specify that you want to update those references. For more information, see How to: Preview Refactoring Changes.

  4. (Optional) Select the Assume default project schema dbo for unqualified script and unit test references check box.

    If you do not select this check box or specify fully qualified names in the scripts and unit tests, you cannot update those references by using refactoring. If you select the check box but you do not specify fully qualified names in the scripts and unit tests, the default schema for these objects and for the project is assumed to be the same.

  5. (Optional) Select the Update references in schema objects containing warnings or errors check box.

    If you clear this check box, references within objects whose definitions result in warnings or errors are not updated. If you select the check box, references are updated regardless of whether the object definitions in which they appear result in warnings or errors.

  6. Click OK.

    If you selected the Preview changes check box, the Preview Changes dialog box appears. Otherwise, the object name is updated, and the object appears in its new location in Schema View.

    Note

    If you moving an object to the another schema, you do not change the name of the file in which the object is defined. If you want to update the file names, you must rename them in Solution Explorer.

    In addition to the optional log files mentioned in step 6, whenever you move a database object to a different schema, entries are written to the ProjectName.refactorlog file. This file is part of your database project and is used when you deploy the database project. You must check it in to version control and manage the file as you would any other shared project asset. For more information, see Move a Database Object to a Different Schema.

See Also

Tasks

How to: Deploy Database Refactoring Changes

Concepts

Move a Database Object to a Different Schema

Fully Qualify the Names of Database Objects

Expand Wildcard Characters in SELECT Statements

Rename References to a Server or Database

Rename All References to a Database Object