How to: Rename Database Objects
This topic explains how to rename a database object in Visual Studio Premium. 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
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.
Note
In Visual Studio Premium, you refactor database objects by using the Schema View window. You cannot refactor database objects from a code window.
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.
Note
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.
In New name, type the new name of the object.
(Optional) Select the Preview changes check box.
Note
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.
(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.
(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.
Note
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.
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.
Note
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
In the Rename dialog box, type the new name of the object.
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.
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.
Click any one of the .sql nodes.
The lower pane displays the Transact-SQL code with the new name highlighted.
Click Apply.
The changes are made. The object name is updated, and you can see the new name in Schema View.
Note
You can undo the changes. For more information, see How to: Undo a Database Refactoring Operation.
See Also
Tasks
Walkthrough: Apply Database Refactoring Techniques
How to: Deploy Database Refactoring Changes