求解一个存储过程 或者 触发器
问题是这样的:
有表A,表B ,表A与表B有ID关联;(注:表A的一条记录与表B的多条记录有ID关联)
同时有表C,表A与表C有ID关联;
还有表D,表D与表与表C有字段关联;
现在需要在删除表A的一条记录时,同时删除表B的多条记录,并且还要删除表D的相关联的一条记录。
求大牛帮忙解决一下,这个存储过程或者是触发器怎么写,困恼了很久了。
[解决办法]
delete from a where id='?';
delete from b where id in(select b.id from a,b where a.id=b.id and a.id='?');
delete from d where id in(select c.字段 from a,c,d where a.id=c.id and c.字段=d.字段 and a.id='?');