REF : https://blog.csdn.net/weixin_44724691/article/details/105280025
표 1. 건설
DROP TABLE IF EXISTS SC_U;
create table SC_U
(
Sno char(9) ,
Cno char(9) ,
oldgrade smallint ,
newgrade smallint ,
)
트리거를 설정합니다 (참고 : 좋은 교육 자료 SC 테이블의 설립을 사전에 따라)
create trigger SC_T
on SC
for update
as declare @old smallint--
--声明变量
declare @new smallint
declare @Sno char(9)
declare @Cno char(4)
if(update(Grade))
begin
select @old =Grade from deleted
select @new =Grade from inserted
select @Sno =Sno from SC
select @Cno =Cno from SC
insert into SC_U(Sno,Cno,oldgrade,newgrade)
values(@Sno, @Cno,@old,@new)
end
3. 테스트
update SC
set Grade=62
where Sno='2017' and Cno ='刘'
select *from SC
select *from SC_U