I have a table in a database:
- MyTable
Other have foreign key constraints to MyTable's Id column:
- MyOtherTable1
- MyOtherTable2
I need to backup MyTable as is.
The task I am going to do is a data conversion. While the data conversion works in QA, our change control requires that we have to have a rollback process in place. I don't plan to actually have to restore the table as is, but I have to prove that I can before change control lets me make the change.
The system is a live order system. I cannot restore the whole database because many orders will go through between the time the change is made and when I will know if I have to restore.
I already figured out how to backup the table.
SELECT * INTO MyTable_Bak FROM MyTable;
However, restoring the table is not working. I cannot do this:
DELETE FROM MyTable
SELECT * INTO MyTable FROM MyTable_Bak;
The above fails because of foreign key constraints.
I am not looking for a $oftware. I know Red Gate and other tools could do this.
The tools available to me are:
- SQL Management Studio
- Admin privileges to the database
Additional Requirements
- The data in every column most be identical after the restore. Id, dates, etc.
- The table cannot be dropped
- Rows in MyOtherTable1 or MyOtherTable2 cannot be changed or deleted.
Note: With this detailed of a question, I detected the smaller parts of this problem one by one as I wrote the question and solved each problem seperately. Do I keep the question and answer it myself or delete it? Since I found no similar question and answer, I will keep it.