简体   繁体   中英

MySQL Update all values from another table

I have two tables original and original_backup , I'm creating a rollback script that takes all the data from original_backup and puts it back into original , the issue I have is there are around 60 columns. Is there an easy way to move all data using an UPDATE and SET without specifying every column?

For example something like: UPDATE original SET * FROM original_backup WHERE original.id = original_backup.id;

Using REPLACE is NOT an option in this case.

You can do it as a two step thing:

DELETE FROM original
INSERT INTO original SELECT * FROM original_backup

This will take some time. To cut over more cleanly:

CREATE TABLE original_restored AS SELECT * FROM original_backup
RENAME TABLE original TO original_prev, original_restored TO original

This is the my solution but im not use UPDATE statement:

1) Delete all data from original

2) run select insert query

something like this:

INSERT INTO original (Field1, Field2)
SELECT a.Field1, a.Field2
FROM original_backup a
INNER JOIN original b ON a.ID = b.ID

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM