Search code examples
sqlsql-serverforeign-keyssql-drop

SQL drop table and re-create and keep data


On our original design we screwed up a foreign key constraint in our table. Now that the table is full of data we cannot change it without dropping all of the records in the table. The only solution I could think of is to create a backup table and put all of the records in there, then delete all the records, alter the table and start adding them back. Any other (BETTER) ideas? Thanks!

Using MS SQL Server


Solution

  • This is your only solution.

    Create the backup table, empty the original one, modify the table and then insert step-by-step until you find a violation.