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.
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.
In the pop-up window, change the object name, tick “Preview Changes” & click OK.
The Preview shows each dependent object that will be changed as part of the refactor. Click Apply to confirm the change.
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.
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.