将数据归档到mysql中
编辑
让我调整一下我的问题,如果我编写了一个脚本,将当前的mysql表复制到存档表,然后从原始表中删除记录,我如何确保保留自动增量?我需要确保主键在存档表中不重复。
EDIT
Let me adjust my question, if I wrote a script that copies a current mysql table to an archiving table then delete the records from the original table how can I make sure the auto increment is preserved? I need to make sure the primary keys are not duplicated in the archived tables.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无需保留归档表中的主键位置。只需确保在复制到存档表时使用 INSERT IGNORE INTO...,您就无需担心存档表中存在重复条目。然后只需对归档表中主键的列使用唯一约束即可。您的归档表上不应该有自动递增的主键。
There is no need to preserve the primary key position in the archiving table. Just make sure that when you copy to the archiving table you use INSERT IGNORE INTO... and you won't need to worry about duplicate entries into the archiving table. Then simply use a unique constraint on the column of the primary key in the archiving table. You should not have an auto-incrementing primary key on your archiving table.