create trigger t1 on getbook for insert
as
update bookstores set booksum = booksum - sum(B.bookcount)
from bookstores as A, inserted as B where A.bookid = B.bookid
go
as
update bookstores set booksum = booksum - sum(B.bookcount)
from bookstores as A, inserted as B where A.bookid = B.bookid
go
as
update bookstores set booksum=booksum-B.bookcount
from inserted a where a.bookid=bookstores.bookid
go
as
update bookstores set booksum=bookstores.booksum-a.bookcount
from inserted a where a.bookid=bookstores.bookid
go
as
update bookstores set booksum=bookstores.booksum-a.bookcount
from (select bookid,sum(bookcount) bookcount from inserted group by bookid) a where a.bookid=bookstores.bookid
go