Press "Enter" to skip to content

Rename objects in SSDT

Aim: Rename objects in SQL Server Data Tools (SSDT) without breaking dependencies.

You can rename SSDT objects in their definition (.sql) files however this does not update the name of the object throughout the project. Renaming an object in this way will break any references to the object in dependent objects (e.g. views or stored procedures).

For example, in the following project, renaming a table from “testTable” to “newTestTable” results in Build errors due to the view that references the object’s old name.

01_rename_via_solution_explorer

However, the SQL Server Object Explorer from the View menu gives us more useful options to refactor objects. In the SQL Server Object Explorer, expand the Project folder & the relevant object subfolder. Right-click the object (e.g. testTable), select Refactor & Rename.

02_sql_server_object_explorer

In the pop-up window, change the object name, tick “Preview Changes” & click OK.

03_rename

The Preview shows each dependent object that will be changed as part of the refactor. Click Apply to confirm the change.

04_preview

Following completion of the refactor, the build will succeed as the dependent objects no longer reference the object’s old name. However, object’s definition file names will not be updated so you may need to align them to the new object names by updating them in the Solution Explorer.

05_successful_build

In the Solution Explorer, you will also see that the project now contains a .refactorlog file containing details of all refactors applied to the project.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *