mysql 删除多个表
是否可以从多个表中删除?
我有3个表,所有表都通过一个id相关,因此如果id相同,则删除相关信息。
非常感谢
is it possible to delete from multiple tables?
i have 3 tables all related by an id, so where the id is the same delete the relevant information.
many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要为表指定 ON DELETE CASCADE 规则。查看有关外键的 MySQL 文档 。级联规则正是您强制数据完整性所需的。
通过正确指定这些规则,当您删除父行时,RDBMS 将自动删除所有子行。
You need to specify ON DELETE CASCADE rule for your tables. Have a look at MySQL docs on foreign keys. Cascading rules are exactly what you need to force data integrity.
With those rules properly specified when you delete the parent row all children rows will be automatically deleted by RDBMS.
在InnoDB中,您可以通过将其设置为级联外键来拥有外键。请参阅此处: http://dev.mysql .com/doc/refman/5.5/en/innodb-foreign-key-constraints.html
In InnoDB you can have a foreign key by setting it up as foreign keys to cascade. Please see here: http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html