mssqltips logo

Refactoring existing database objects using SSDT



By:

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

Last Update: 7/22/2014




More SQL Server Solutions











Post a comment or let the author know this tip helped.

All comments are reviewed, so stay on subject or we may delete your comment. Note: your email address is not published. Required fields are marked with an asterisk (*).

*Name
*Email
Email me updates

Signup for our newsletter

I agree by submitting my data to receive communications, account updates and/or special offers about SQL Server from MSSQLTips and/or its Sponsors. I have read the privacy statement and understand I may unsubscribe at any time.





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

 

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 ?



download





get free sql tips

I agree by submitting my data to receive communications, account updates and/or special offers about SQL Server from MSSQLTips and/or its Sponsors. I have read the privacy statement and understand I may unsubscribe at any time.



Learn more about SQL Server tools