Pages

Men

rh

10/16/2015

Refactoring existing database objects using SSDT

Overview

Databases are made to be refactored. Objects are always being modified as a database evolves. How can changes be accomplished?

Explanation

Refactoring existing database objects is just as easy as adding new objects. Let's refactor the Team table'sCity column to CityName.
Within the Solution Explorer, double click on the Team.sql file. This will present the dual Design/T-SQL panes. Within the T-SQL pane, right click on the City column and choose Refactor and Rename:
Refactor City column
You will be presented with the Rename dialog. Change City to CityName and click OK
Rename City to CityName
Note the checked Preview changes check box. This allows you to examine the changes before they're applied.
Preview Changes
Clicking Apply ripples the change of City to CityName throughout our project including to the post-deployment script we created for initial data insert. As a by product of the refactor, a Futbol.refactorlog file is created inside the Solution Explorer.
Now let's publish these changes. Remember the FutBol.publish.xml file we saved previously? We can now leverage it. In the Solution Explorer, double clicking on this file presents the Publish Database with the target instance pre-filled. If we had any advanced options modified from their defaults, they'd be included automatically as well.
Publish Database
Just click Publish and examine the Output pane:
Data Tools Operations Output
Examining our SQL Server database, we can see the change from City to CityName has been applied:
SSMS Output
 
source collected from mssqltips.com

No comments :

Post a Comment