delete b where content is null go delete t where not exists(select 1 from b where tid=t.id) go
delete b where content is null delete t from t inner join b on t.id=b.tid where b.content is null
delete t from t inner join b on t.id=b.tid where b.content is null delete b where content is null
试一下delete t ,b from b left join t on b.id = t.id where b.content is null
首先的问题是tid是主键还是T表中ID是主键? 如果要删除两条相应记录要先删除外键表,后主键表。因为外键的值在主键表里一定要有,所以删除要注意先后。 如果T中id是主键则: 即: delete b where content is null --删除b中记录 delete t where t.id not in(select tid from b) //这个语句很可能有错误,但是大概思路是这样 如果tid是主键。 则: delete t from t inner join b on t.id=b.tid where b.content is null delete b where content is null
delete t from t inner join b on t.id=b.tid where b.content is null and len(b.content)=0 delete b where content is nulland len(b.content)=0 可以满足,但最好用触发器
go
delete t where not exists(select 1 from b where tid=t.id)
go
delete t from t inner join b on t.id=b.tid where b.content is null
delete b where content is null
from
b left join t on b.id = t.id where b.content is null
如果要删除两条相应记录要先删除外键表,后主键表。因为外键的值在主键表里一定要有,所以删除要注意先后。
如果T中id是主键则:
即:
delete b where content is null --删除b中记录
delete t where t.id not in(select tid from b) //这个语句很可能有错误,但是大概思路是这样
如果tid是主键。
则:
delete t from t inner join b on t.id=b.tid where b.content is null
delete b where content is null
delete t from t inner join b on t.id=b.tid where b.content is null and len(b.content)=0
delete b where content is nulland len(b.content)=0
可以满足,但最好用触发器