소개 [T-SQL 데이터베이스 시스템 [}] 예 5.21

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

 

 

 

게시 40 개 원래 기사 · 원 찬양 80 ·은 10000 +를 볼

추천

출처blog.csdn.net/qq_38975453/article/details/105326192