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

    插入触发器:

    if (object_id('tgr_Category_insert', 'tr') is not null)
        drop trigger tgr_Category_insert
    go
    create trigger tgr_Category_insert
    on Category
        for insert --插入触发
    as
        --定义变量
        declare @CGID int,@CGType tinyint;
        --在inserted表中查询已经插入记录信息
        select @CGID = CGID,@CGType=CGType from inserted;
        if(@CGType=1)
        begin
            insert into Advertisements (CGFstID,CurrentAdvert,ModifyDate,Operator,ImgUrl,ImgGotoUrl,AdvertCode)
            values (@CGID,0,getdate(),'','','','')
        end   
    go

    删除触发器:

    if (object_id('tgr_Category_delete', 'tr') is not null)
        drop trigger tgr_Category_delete  
    go
    create trigger tgr_Category_delete 
    on Category  
        for delete --删除触发  
    as  
        --定义变量  
        declare @CGID int,@CGType tinyint;  
        select @CGID = CGID,@CGType=CGType from deleted;  
         if(@CGType=1)  
         begin  
          delete from Advertisements where CGFstID=@CGID  
         end       
    go

    查询触发器语句:

    use jxcSoftware --数据库名称
    go
    select * from sysobjects where xtype='TR'
  • 相关阅读:
    SVN服务器搭建和使用(一)
    SVN服务器搭建和使用(一)
    lua loadstring与loadfile
    lua loadstring与loadfile
    lua_getstack
    lua_getstack
    让程序在崩溃时体面的退出之Dump文件
    bzoj1054
    poj3678
    poj2749
  • 原文地址:https://www.cnblogs.com/wxh19860528/p/3412610.html
Copyright © 2011-2022 走看看