57.5. Database Refactoring

We talked about refactoring in Chapter 17. For databases you have only one refactoring task, Rename. If you install the Power Tools described at the end of this chapter, you will have additional refactoring tasks like Move Schema and Extend to Type DataSets, but we won't cover these here.

You can rename tables, columns, stored procedures, constraints, and indexes as well as other database objects. You can also rename the references to other servers or databases if a cross-database reference is used in the scripts.

To rename an object from the Schema View, right-click it and select Rename from the Refactor sub-menu. When renaming an object you will see a preview of the changes as shown in Figure 57-6. In the upper pane you will see the old version and in the lower pane the new one for all the dependencies.

Figure 57.6. Figure 57-6

Renaming is easily done on an offline schema version, but for tables and columns it can be hard to deploy to the database. Because the old object will be dropped and re-created, this can result in data loss. If you have a Data Generation Plan, you can regenerate the data after the changes are deployed, but if you need to preserve your data you should either modify the deployment script or apply the refactoring manually. See "Protecting Data during a Renaming Operation" on MSDN for more information.

Get Professional Visual Studio® 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.