将行迁移到新表,然后删除它们
我有一个大型产品数据库,每天我希望运行一个脚本,将 active = '1' 的行移动到新表中并删除原始行。
但我似乎找不到合适的 Mysql 命令来完成迁移。
如果有人能够阐明这一情况,那就太好了。
多谢
I have a large database of products and everyday I wish to run a script that moves rows with active = '1' into a new table and deletes the original row.
But I can't seem to find the appropriate Mysql command to accomplish the migration.
It would be great if someone could shed some light on the situation.
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够通过以下内容完成此操作
正如好奇,这样做的意义何在?如果您担心模糊行,可以按如下方式删除
You should be able to complete this with the following
Just as curiosity, what is the point of doing this? If you're worried about the fuzzy rows you could do the delete as follows
没有任何细节,您将执行以下操作:
创建一个 INSERT 语句到新表 AS SELECT from the old table WHERE active = 1。
创建一个 DELETE 语句,从第一个表中删除在第二个表中找到的任何行。
犯罪;
without any details, here is what you will do:
create an INSERT statement to the new table AS SELECT from the old table WHERE active = 1.
create a DELETE statement that deletes from the first table any rows it finds in the second table.
commit;