如何删除2个表里相关的数据?
A:
id hyid hynumber isok
123 123 1001 0
133 135 1002 1
B:
id hyname
123 李
135 陈
(注:A.hyid=B.id)
如何删除A表里isok=0的那条数据,并删除B表中关联的数据?谢谢~~~
------解决方案--------------------Delete From A Where isok = 0
Delete B From A Inner Join B On A.id = B.id Where A.isok = 0
------解决方案--------------------delete b where id in (select hyid from a where isok=0)
delete a where isok=0
------解决方案--------------------Create Trigger Delete_B On A
For Delete
As
Delete B From Deleted A Inner Join B On A.id = B.id
GO
------解决方案--------------------delete b from a,b where A.hyid=B.id and a.isok=0
delete a where isok=0