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

    exec sp_rename '原名','新名'

    select * into tbsales from sales

    例子1:

    create trigger [dbo].[DeleteFileCommentById] 
    on [dbo].[INFO_FILE_ATTRIBUTE] 
    for delete 
    as 
    begin 
    DECLARE @FileIndex int 
    SELECT @FileIndex = FileIndex FROM deleted 
    delete dbo.INFO_FILE_COMMENT where fileindex=@FileIndex 
    end

    例子2:

    create trigger updateVoteSum

    on voteDetails

    for update

    as

    begin

    update voteMaster set voteSum = voteSum+1 where id=(select top 1 id from inserted)

    end

    go

    例子3:

    Create trigger trInsUpdsales

    on tblSales

    for insert,update as

    if(select count(*) from tblstores,inserted where tblstores.stor_id=inserted.stor_id)=0

    Begin

    print 'the stor_id you have entered does not exist'

    Rollback transaction

    End

    例子4:(havescore)

    CREATE TRIGGER tr_updates ON dbo.AICC_BLOCK_HIGH_SCORE

    FOR  update

    AS

    declare @id1 char(10)

    declare @id2 decimal(10)

    declare @id3 varchar(255)

    declare @id4 varchar(255)

    select @id1=browse_score,@id2=block_high_num,@id3=COURSE_ID,@id4=student_id

    from inserted

    if @id1 < 0

    begin

          update aicc_block_high_score set browse_score='0' where block_high_num= @id2

    end

    if  @id1 >=90

    begin  

          update user_course_reg set credit_hour=(select credit_hour from courseware where course_number=@id3),active_date=getdate() where course_id=(select course_id from courseware where course_number=@id3)  and user_nm=(select user_nm from users where user_id=@id4)   and (credit_hour='0' or credit_hour is null ) 

    end 

    if @id1 > 90

    begin

          update aicc_block_high_score set browse_score='100' where block_high_num= @id2

    end

  • 相关阅读:
    【剑指Offer】21、栈的压入、弹出序列
    【剑指Offer】20、包含min函数的栈
    【剑指Offer】19、顺时针打印矩阵
    【Shell编程】Shell基本语法
    【Shell编程】Shell程序设计
    linux 大中括号变量解读
    Python 二进制,十进制,十六进制转换
    Python3.x和Python2.x的区别
    python通过SSH登陆linux并操作
    PEP8特性
  • 原文地址:https://www.cnblogs.com/cw_volcano/p/1947524.html
Copyright © 2011-2022 走看看