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

解决方案 »

  1.   

    create trigger t1 on getbook for insert
    as
    update bookstores set booksum=booksum-B.bookcount
      from inserted a where a.bookid=bookstores.bookid
    go
      

  2.   

    更正:create trigger t1 on getbook for insert
    as
    update bookstores set booksum=bookstores.booksum-a.bookcount
      from  inserted a where a.bookid=bookstores.bookid
    go
      

  3.   

    或:create trigger t1 on getbook for insert
    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