Home  >  Q&A  >  body text

数据库 - Mysql中,一张表的数据删除的同时,在另一张表中插入的问题。

问题可能很小白。

想做到如下效果:
有一张表(关联了其他很多表),删除其中数据,同时在另一张表中插入一条同样的数据,以用作备份。。

功能就是这样,备份这条数据可在日后直接恢复到生产环境中。

这时该怎么做呢,有没有什么数据库黑科技可以简单实现呢。。

我删除一条数据在另一个表中插入一条,这种效率吗?有别的方法可以做吗。

谢谢大家。

怪我咯怪我咯2742 days ago633

reply all(3)I'll reply

  • 迷茫

    迷茫2017-04-17 14:23:53

    Use triggers to implement this, but this is not recommended. You can add a field to the table to mark it as deleted

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 14:23:53

    Have you considered using transaction processing? At the same time, the poster can change his mind and add this record to the backup table first, and then delete this data. Don’t worry, this process must use transactions to maintain event consistency!

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 14:23:53

    Possibly the trigger will have the least impact on the existing system and require the fewest conditions to be met

    reply
    0
  • Cancelreply