create trigger GrUpdate
on [dbo].[SC]
after insert,update
as
declare @befGr smallint,@afrGr smallint
if UPDATE(Grade)
begin
select @befGr=DELETED.Grate from DELETED
select @afrGr=INSERTED.Grate from INSERTED
INSERT INTO [JXGL].[dbo].[Gradechange]
([usename]
,[changetime]
,[bfch_value]
,[afch_value])
VALUES
(USER_NAME()
,GETDATE()
,@befGr
,@afrGr)
end
报错:
Msg 207, Level 16, State 1, Procedure GrUpdate, Line 8
Invalid column name 'Grate'.
Msg 207, Level 16, State 1, Procedure GrUpdate, Line 9
Invalid column name 'Grate'.
求大神帮忙
------解决方案--------------------
好像是把,grade写成了grate了,改成这样试试:
create trigger GrUpdate
on [dbo].[SC]
after insert,update
as
declare @befGr smallint,@afrGr smallint
if UPDATE(Grade)
begin
select @befGr=DELETED.Grade from DELETED
select @afrGr=INSERTED.Grade from INSERTED
INSERT INTO [JXGL].[dbo].[Gradechange]
([usename]
,[changetime]
,[bfch_value]
,[afch_value])
VALUES
(USER_NAME()
,GETDATE()
,@befGr
,@afrGr)
end
------解决方案--------------------
触发器,当然是一条一致行的呀。
------解决方案--------------------
在sql server中的触发器,不是行级触发器,不能实现一行一行的处理,而是比如你要更新100条数据,那么只会触发一次。
只有在oracle中,才支持行级别的触发器。
------解决方案--------------------
批量更新用下面这个试试。
create trigger GrUpdate
on [dbo].[SC]
after insert,update
as
--declare @befGr smallint,@afrGr smallint
if UPDATE(Grade)
begin
--select @befGr=DELETED.Grade from DELETED
--select @afrGr=INSERTED.Grade from INSERTED
INSERT INTO [JXGL].[dbo].[Gradechange]
([usename]
,[changetime]
,[bfch_value]
,[afch_value])
SELECT
USER_NAME()
,GETDATE()
,B.Grade
,A.Grade
FROM inserted A
LEFT JOIN deleted B ON A.usename = B.usename
end