SQL Server创建一个触发器并进行验证
作者:互联网
--创建一个Borrow表触发器使Borrow执行insert语句,Readers表借书数量更新,Books表的相关书籍库存量更新
create trigger B_Insert on Borrow
after insert
as
begin
declare @R_ID char(5),--声明
@B_ID char(5)
select @R_ID=R_ID,@B_ID=B_ID from inserted;--获取参数
update Readers set R_Borrow_Num=R_Borrow_Num+1 where @R_ID=R_ID;--触发启动操作
update Books set B_Num=B_Num-1 where @B_ID=B_ID;
select * from Readers where (R_ID=@R_ID);
select * from Books where (B_ID=@B_ID);
End
--验证
insert into Borrow values('00001','A0004','21.12.12')
标签:触发器,Readers,--,Borrow,Server,Num,SQL,where,ID 来源: https://blog.csdn.net/weixin_54342576/article/details/122249104