关于insert,update的临时表
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
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