Udostępnij za pośrednictwem


How to: Rename References to a Server or Database

You can use database refactoring to automatically update the names of servers, databases, or SETVAR variables in cross-database references throughout your database project. For more information, see Using References in Database Projects.

Name Matching

If you specify both a name (or variable) for a server and a name (or variable) for a database, the renaming operation will update only those references that point to that specific database on that specific server. If you specify a name (or variable) for a server but not for a database, the renaming operation will update all references that include the server name (or variable) that you specified, regardless of the database to which the reference points. If you specify a name (or variable) for a database but not for a server, the renaming operation will update all references that include database name (or variable), regardless of the server to which the reference points. You should review the changes in the Preview Changes dialog box before they are applied.

Note

Before you can follow this procedure, at least one reference must appear in the properties for your database project.

To rename references to a server or database

  1. Open the solution that contains the database project in which you want to rename references. For more information, see How to: Open a Database or Server Project.

  2. In Solution Explorer or Schema View, click the database project in which you want to rename references.

  3. On the Data menu, point to Refactor, and click Rename Server/Database References.

    Note

    You can also right-click the database project in Solution Explorer or Schema View, point to Refactor, and click Rename Server/Database References.

    The Rename references to a server or database dialog box appears.

  4. To replace the name of a server or a server variable:

    1. Select the Replace the name of a server or a server variable check box if it is not already selected.

    2. In Old name, type the name of the server or server variable that you want to replace.

    3. In New name, type the name that you want to use instead of the name that you want to replace.

  5. To replace the name of a database or a database variable:

    1. Select the Replace the name of a database or a database variable check box if it is not already selected.

    2. In Old name, type the name of the database or database variable that you want to replace.

    3. In New name, type the name that you want to use instead of the name that you want to replace.

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

    Note

    For more information about how to preview the changes before you make them, see the next procedure.

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

    You can find the refactoring logs at YourProjectPath\Refactoring Logs.

    Note

    You can rename a reference even though you have build errors in your project. The renaming operation updates as many references to that object as possible, but not all references might be updated.Where possible, you should consider fixing the build errors first and then performing the rename operation. For more information, see Considerations before Renaming Database Objects.

  8. Click OK.

    If you did not select the Preview changes check box, the references to the server or database names or variables are updated.

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

To preview changes before you make them

  1. In the upper pane of the Preview Changes dialog box, expand the Scripts node.

    A .sql node for the schema object that you are renaming (or the object that contains it) appears, together with .sql nodes for any schema objects that refer to the object that you are renaming.

  2. Click any of the .sql nodes.

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

  3. Click Apply.

    The object name is updated, and the new name appears in Schema View.

See Also

Concepts

Using References in Database Projects

Terminology Overview of Database Edition

Other Resources

Overview of Rename Refactoring

How to: Add Cross-database References