Refactoring existing database objects using SSDT



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


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

Comments For This Article

Friday, September 23, 2016 - 7:40:02 AM - Tomasz Back To Top (43400)


Hi Armando, how about the situation when we made a change (rename a column name) just like that without using Refactor change name for multiple tables in SSDT. Is there a way to refactor them all globally ?

get free sql tips
agree to terms