SQL Server rename foreign key constraint 1

SQL Server rename foreign key constraint

sp_rename 'schema_name.old_fk_name', 'new_fk_name';

Here is what the above code is Doing:
1. We’re creating a new table called ‘new_table’ with the same columns as ‘old_table’.
2. We’re inserting all the data from ‘old_table’ into ‘new_table’.
3. We’re dropping the ‘old_table’.
4. We’re renaming the ‘new_table’ to ‘old_table’.

Similar Posts