zoukankan      html  css  js  c++  java
  • trigger 触发器

    --trigger
    --在SC表上建了一个触发器,查看inserted和deleted表中内容。
    create trigger tri_1 on sc
    for insert,update,delete
    as
    --declare @a int
    select * from inserted
    select * from deleted
    go
    drop trigger tri_1
    go
    insert into sc
    values('200215122','1',87)
    go
    update sc
    set grade=90 where sno='200215122' and cno='1'
    go
    select * from sc
    select * from student
    select * from course
    go
    create trigger tri_2 on student
    for insert
    as
    select * from inserted
    declare @a smallint
    select @a=sage from inserted
    if @a<14 
    update student
    set sage=18 where sno=(select sno from inserted)
    go
    drop trigger tri_2
    go
    insert into student
    values('200215127','liusi','男',12,'cs')
    go drop table teacher
    CREATE TABLE teacher
    (Eno    char(4) primary key,
     Sal     smallint,
     tname  char(10),
     job char(8) )
    go 
    create trigger tri_2 on teacher
    for insert
    as
    declare @a char(8) 
    select @a=job from inserted
    if @a='教授' and 4000>(select sal from inserted) 
    update teacher
    set sal=4000 where eno=(select eno from inserted)
    go
    insert into teacher 
    values('1001',3000,'pro_zhang','教授')
    go
    select * from teacher
    go 
    

      

  • 相关阅读:
    OleDbCommand 的用法
    递归求阶乘
    C#重写窗体的方法
    HDU 5229 ZCC loves strings 博弈
    HDU 5228 ZCC loves straight flush 暴力
    POJ 1330 Nearest Common Ancestors LCA
    HDU 5234 Happy birthday 01背包
    HDU 5233 Gunner II 离散化
    fast-IO
    HDU 5265 pog loves szh II 二分
  • 原文地址:https://www.cnblogs.com/wc1903036673/p/3413061.html
Copyright © 2011-2022 走看看