

Once you’ve renamed your table (in this instance from users to customers) the next step would be to commit the changes to your source control system using the Commit changes tab in SQL Source Control. This script replaces the DROP and CREATE statements the SQL Compare engine would otherwise generate for this change. To avoid this data loss, you can write a migration script to rename the table using the sp_rename stored procedure. If another member of your team uses the Get latest tab to get these changes, data in the target table is lost. In the instance of renaming a table on your development database, SQL Source Control would interpret this change as a DROP and CREATE.
#Sql rename table how to#
How to avoid data loss when renaming a tableĬommon tasks which might be affected include splitting or merging columns and tables, adding a NOT NULL constraint to a column, changing the data type or size of a column, and renaming a table. You can learn more about what we’ve done, and why, in another recent blogpost of mine.īut here, I wanted to talk you through how it works using a common scenario. The latest release (shipped this week!) features an improved version of migration scripts, which allow you to write your own SQL to override the deployment script generated by SQL Compare, making it possible for your teammates to get the latest changes from source control without the risk of losing data. SQL Source Control plugs into SSMS and connects your databases to your version control system, allowing you to version control your database schemas, and then deploy them using Redgate’s trusted comparison engine SQL Compare. How to rename a table without data loss in SQL Server Management Studio using migration scripts - Simple Talk Skip to content
