• 触发器


    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

  • 相关阅读:
    Linux中Elasticsearch集群部署
    在.net core 项目中添加swagger支持
    ASP.NET Core 类库中取读配置文件
    Redis的服务安装步骤
    Lambda表达式多表连接的左连
    Angular7 学习资料
    Docker在eShopOnContainer项目中的使用方法
    绘图工具
    万能分页存储过程(SQL Server)
    为什么程序开发人员这么累?
  • 原文地址:https://www.cnblogs.com/cw_volcano/p/1947524.html
Copyright © 2020-2023  润新知