Foreign Key Constraints after Table Rename

5.3k views Asked by At

I'm using FluentMigrator for database migrations on a SQL Server 2014 database. If I use the Rename builder to rename a table as such:

Rename.Table("Old Name").To("NewName");

Do I then need to drop and remake any foreign keys that reference the table's old name or does SQL (or FM) know to update the references?

1

There are 1 answers

3
Pரதீப் On BEST ANSWER

You don't have to worry about foreign keys it will be automatically referring to new table name.

But if the table is used in any stored procedure, function, view or trigger then after renaming the table you have to manually change the scripts to refer the new name else while executing any of the above mentioned objects you will get invalid object name error

As mentioned in comments if the old table name is used in application codes then again you need to manually change it to new table name