var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: Replacing a Messed up table with Backup (SQL Server 2005)
SQL server 2005
kind of new at sql programming
How would I go about replacing all the data in a table with a backup table. In short I inserted like 5000 entries into my main table that shouldn't have been inserted.....
I know I can drop and recreate the table(key issues maybe)...but Im a little hazy in how I would insert all the data from the backup to the original
or maybe there is an option in sql server to restore a table to another table?
Any way you go, you will need to address foreign and primary key issues. If you can easily identify the bad records in the table, go ahead and delete them, and you are done.
if you need to insert records from another table in the database, that can be as easy as
insert into table
select * from table_backup
First you need to have a backup that is before the data got modified
Do you have that?
yeah I have two tables in the database.
with person_backup identical to person before the inserted rows.
and I think it might be easier to learn how to do the sql code instead of going through 5000 entries....
i think i can go
DELETE FROM Person
insert into Person
select * from Person_backup
the insert statement doesn't sit well with me and I am unsure if that is how to do it
Last edited by fff398; 10-15-09 at 13:27.
Try it with some other tables first, until you are confident.
okay it looks like it worked. thanks for the help.
The insert threw me off with the select statement there and since im starting out, ive always used insert to just insert a value.
Also look up sp_rename in BOL
Sounded like he might have had foreign keys pointing at the old table. I don't think those get redirected for sp_rename, but I have not tried it.