触发器中: select id from inserted
这个句子有个情况不适合,
就是如果一次操作插入的是多行,这条语句不就不行了么,
那为什么检查语法时还没错误呢
CREATE TRIGGER TR_ZZ ON ZZ
FOR INSERT
AS
BEGIN
DECLARE @ZZLB VARCHAR(30),
@CSZ NUMERIC(9,1),
@ZZS NUMERIC(9,1),
@ZZBH BIGINT
declare cur insensitive cursor for
select ZZBH,ZZLB,ZZS from inserted for read only
open cur
fetch next from cur into @ZZBH,@ZZLB,@ZZS
while( @@fetch_status <> -1 )
begin
IF @ZZLB='专著'
SET @CSZ=(SELECT CSZ FROM CSFZ WHERE CSDH='61')
ELSE
SET @CSZ=(SELECT CSZ FROM CSFZ WHERE CSDH='62')
UPDATE ZL
SET ZZFS=@ZZS*@CSZ
WHERE ZL.ZZBH=@ZZBH
fetch next from cur into @ZZBH,@ZZLB,@ZZS
end
close cur
deallocate cur
END