如何在另一个表中缺少值后清理表?
我尝试将 bbPress 1.0 安装迁移到 WordPress 上的新 bbPress 2.0 插件,但没有成功,这使我的 wp_posts
表变得一团糟。
我通过删除对 post_type
列携带 topic
和 reply
值的所有帖子解决了这个问题,这很好。
但现在我注意到 wp_postmeta
似乎受到许多引用我已删除的帖子的条目的影响。两个表都有 post_id
列。
问题是:我使用哪个 SQL 命令来删除 wp_postmeta
上引用不再位于 wp_posts
上的行的值?我知道这是我应该使用的某种连接,但我不知道如何查找不存在的内容并将其删除。
PS:WordPress 表格不保持引用完整性是怎么回事?我非常确定在删除 wp_posts
上的相关内容时可以自动从 wp_postmeta
中删除某些内容。那好吧…
I was unsuccessful trying to migrate a bbPress 1.0 instalation to the new bbPress 2.0 plugin on my WordPress, which made quite a mess on my wp_posts
table.
I solved that by deleting every posts who was carrying the values topic
and reply
to the post_type
column, and that was good.
But now I noticed that the wp_postmeta
seems affected by lots of entries refering to posts that I've deleted. Both tables have the post_id
column.
The question is: which SQL command I use to delete the values on wp_postmeta
referencing lines who aren't anymore on wp_posts
? I know it's some kind of join that I should use but I don't see how it would be to look for something who is not there and delete it.
PS: And what's up with WordPress tables not keeping referential integrity? I'm pretty sure it's possible to delete something automatically from wp_postmeta
when deleting something related on wp_posts
. Oh well…
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
手动删除表 a 中与表 b 中不匹配的行的一般方法是:
这可能不是执行批量删除的最有效方法(联接可能会更快),但我通常更喜欢在以下情况下使用子选择这样,它更容易理解,因此降低了 FUBAR 概率(您不想意外删除 table_b 等中的行),
因此在您的情况下,您可能可以这样做:
如果您确定,这些是您想要的行要删除,请将 SELECT * 替换为 删除:
a general way to manually delete rows from table a that have no match in table b is:
this may not be the most efficient way to do a mass delete (joins could probably do it faster), but I usually prefer a subselect in cases like this, it is easier to understand and therefore reduces the FUBAR probability (you don't want to accidentally delete rows in table_b etc)
so in your case you could probably do something like this:
if you are sure, these are the rows you want to delete, replace SELECT * with DELETE:
是的,您想使用外连接。
许多较新的应用程序现在使用实体框架,并且不显式强制执行引用完整性,仅强制执行关系。例如,Atlassian JIRA 不强制执行引用完整性。
Yes, you want to use outer joins.
A lot of newer applications now use entity frameworks and don't explicitly enforce referential integrity, just relationships. Atlassian JIRA, for example, doesn't enforce referential integrity.