Export (0) Print
Expand All

How to: Rename Database Objects

This topic explains how to rename a database object in Visual Studio Team System Database Edition. When you rename a database object, other objects that reference the renamed object are automatically updated with the new name. For example, if you rename a column in a table, any stored procedures that reference that column are automatically updated with the new name. For more information, see Rename All References to a Database Object.

To rename a database object

  1. In Schema View, click the object that you want to rename. For example, to rename a column, expand the Tables subfolder, expand the table, expand the Columns folder, and click the object that you want to rename.

    NoteNote:

    In Database Edition, you refactor database objects by using the Schema View window. You cannot refactor database objects from a code window.

  2. On the Data menu, point to Refactor, and then click Rename. You can also right-click the object in Schema View, point to Refactor, and then click Rename.

    The Rename dialog box appears.

    NoteNote:

    You cannot rename a database object if the object that you are trying to rename contains build errors. In that case, the menu option is unavailable.

  3. In New name, type the new name of the object.

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

    NoteNote:

    For details about how to preview the changes before you make them, see the next procedure. By default, references in unit tests and scripts are not updated automatically. You must use the Preview Changes dialog box to apply those changes.

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

    If the check box is cleared and you do not specify fully qualified names in the scripts and unit tests, those references are not found. If the check box is selected and you do not specify fully qualified names in the scripts and unit tests, the default schema for these objects is assumed to be the same as the default schema of the project.

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

    If the check box is cleared, references within objects whose definitions result in warnings or errors will not be included in the refactoring operation. If the check box is selected, all references will be updated, even if the containing object definition contains warnings or errors.

  7. (Optional) Select the Generate refactoring log check box.

    You can find the refactoring logs at <YOUR PROJECT PATH>\Refactoring Logs. These logs are separate from the ProjectName.refactorlog file that helps preserve the intent of your refactoring operations when you deploy the database project.

    NoteNote:

    If you rename a database object when you have build errors in your project, the object can still be renamed correctly. However, not all references to that object might be updated correctly. If your project contains build errors, the object is renamed, and as many references are updated as possible. You can also fix the build errors first and then perform the rename operation. For more information, see Considerations before Renaming Database Objects.

  8. Click OK.

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

    NoteNote:

    You can undo the changes. For more information, see How to: Undo a Database Refactoring Operation.

    In addition to the optional log files that are mentioned in step 6, entries are written to the ProjectName.refactorlog file whenever you move a database object to a different schema. 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.

To preview changes before you make them

  1. In the Rename dialog box, type the new name of the object.

  2. Select the Preview changes check box, and click OK.

    The Preview Changes dialog box appears and contains an upper pane and a lower pane. The upper pane contains a tree that lists the objects that will be changed, and the lower pane shows the script that will be generated to make the changes. The upper pane displays the old name, and the lower pane displays the new name.

  3. In the upper pane, expand Schema Objects.

    A .sql node for the schema object that you are renaming (or the object that contains it) appears, along with .sql nodes for any schema objects that reference the renamed object.

  4. Click any one of the .sql nodes.

    The lower pane displays the T-SQL code with the new name highlighted.

  5. Click Apply.

    The changes are made. The object name is updated, and you can see the new name in Schema View.

    NoteNote:

    You can undo the changes. For more information, see How to: Undo a Database Refactoring Operation.

Community Additions

ADD
Show:
© 2014 Microsoft