我想只在其父表中存在父项时插入行。Mysql - 检查行是否存在
线程1台
id | content |
1 | Hello World |
2 | Bye World |
线程2台
id | content |
1 | Naruto |
2 | DragonBallz|
评语表
id | thread_id| thread_type | content |
1 | 1 | thread1 | hellow |
2 | 1 | thread2 | bye-bye |
现在,如果我这样做
INSERT INTO comment(thread_id,thread_type,content)VALUES('3','thread2','Whatever');
应该失败,因为3
不存在于thread2
表。
这可以通过检查线程表来实现。但没有它可能吗?没有做额外的查询?
更新
上面的表已经更新。在thread_type
指表thread1
& thread2
是否有可能在插入时会知道thread_type? –
您应该考虑为线程创建一个表,并在该表中为'thread_type'创建一个字段,而不是。 – deed02392