0

I have problem while dealing with copy of database table entry from one file to other .

suppose i have two tables called one.sql , two.sql , now i wana transfer some record from one.sql to the table two.sql, then delete that entry from one.sql ater copying success.

problem : suppose power was gone after i make copy from one to two, the delete record from one wasnt done , here in that case same record will be in both tables. that i dont want. so in this situation how to handle these types of inconsistent on fly.

4

2 回答 2

3

您的 RDBMS不是一个简单的数据存储!它支持日志事务隔离原子更新。所以...

...使用事务表(InnoDB)和良好的隔离级别只需执行以下操作:

START TRANSACTION -- Or SET autocommit = 0
INSERT INTO two SELECT * FROM one WHERE ...;
DELETE FROM one WHERE ...;
COMMIT

COMMIT原子性会将更改应用于数据库。也就是说,从其他事务的角度来看,移动要么完成,要么没有开始。没有人能看到它完成了一半。即使发生灾难性故障(停电)。

当然,如果您移动所有记录,您也可以依靠RENAME TABLE...

于 2013-07-30T10:37:53.533 回答
1

您可以使用事务块在一定程度上减少意外结果。但解决电源问题是另一回事。

但是,如果您担心电源问题,您可以使用批处理并检查两个表是否在某个时间间隔不包含相同的记录。

于 2013-07-30T10:45:01.900 回答