27,579
社区成员
发帖
与我相关
我的任务
分享
--上面的那个理解有点问题,特修正一下。
create trigger Book_on_insert
on books
instead of insert
as
if exists(select 1 from books a,inserted b where a.ISBN=b.ISBN)
update a set 数量 = a.数量 + 1 from books a,inserted b where a.ISBN=b.ISBN
else
insert books select * from inserted
--可以没有主键,但你要有一个唯一性字段,如
--如果不存在的话,自然会插入的。
create trigger Book_on_insert
on books
for insert
as
if exists(select 1 from books a,inserted b where a.ISBN=b.ISBN)
update a set 数量 = a.数量 + 1 from books a,inserted b where a.ISBN=b.ISBN