假设有a,b两个表,
a 表字段 aid bid
b表字段 bid
删除a表中一条记录时,执行一个触发器,能实现以下两个功能
1 a.bid在b表中是否存在,如果存在则删除。那么如何获取a表当前选中行的bid.
2 如果删除a表中多行数据,同时能够删除b表中对应的数据。
a 表字段 aid bid
b表字段 bid
删除a表中一条记录时,执行一个触发器,能实现以下两个功能
1 a.bid在b表中是否存在,如果存在则删除。那么如何获取a表当前选中行的bid.
2 如果删除a表中多行数据,同时能够删除b表中对应的数据。
create table b(bid int)insert a select 1,1
insert a select 1,2
insert a select 1,3insert b select 1
insert b select 2create trigger t_test on a
for delete
as
delete b from deleted a,b b where a.bid=b.bid
delete from a where bid in(2,3)select * from b
bid
-----------
1(1 行受影响)
create trigger triname on a
for delete
as
delete b
from deleted a,b b
where a.bid=b.bid
获取这个BID?
--2005
delete from a output deleted.BID
SQL 2000不支持