I have generated some SQL Server(2008) upgrade scripts using SqlCompare. The primary objective is to add a null column. However, the generated script wants to drop foreign keys in a couple of other tables and the primary key of the target table before the add column. It then re-adds them. Is this necessary? What is the reasoning behind doing it?.
Sql-server – Is it necessary to drop foreign keys before adding a null column to a table and then re-add them
foreign keysql-server-2008
Related Question
- Sybase ASA: Saving and dropping all foreign keys and most Primary Keys for (Bulk) Insert
- Sql-server – Clustered columnstore indexes and foreign keys
- Sql-server – Cascade primary key update to all referencing foreign keys
- Mysql – Performance impact of adding a foreign key to a 1M rows table
- Postgresql – Inheritance and foreign keys in Postgres
Best Answer
No it is not necessary. See this working example below:
As you can see by the code, I modify
dbo.ParentTable
by adding a column. That is a successful operation with the primary key constraint still in place.As to why your third party software does this, we could guess all day. But most likely they do it to handle some corner case without first testing whether or not the current operation falls into that.