zoukankan      html  css  js  c++  java
  • SQLServer触发器的使用

    创建一个触发器

    CREATE TRIGGER decor--触发器名称
       ON dbo.SG_DecorationEntry --表名
       AFTER INSERT --操作(增删改)
    AS 
    BEGIN
        DECLARE @id UNIQUEIDENTIFIER 
        SELECT @id=Inserted.DecorationEntryID FROM Inserted --添加操作时的数据
        --需要执行的业务
        INSERT INTO dbo.SG_DecorationEntryAPLog
                ( DecorationEntryAPLogID ,
                  DecorationEntryID ,
                  ApprovalAction ,
                  ApprovalUser ,
                  ApprovalDate ,
                  ApprovalOpinion ,
                  ApprovalUserCode
                )
        VALUES  ( NEWID() , -- DecorationEntryAPLogID - uniqueidentifier
                  @id , -- DecorationEntryID - uniqueidentifier
                  N'' , -- ApprovalAction - nvarchar(50)
                  N'' , -- ApprovalUser - nvarchar(50)
                  GETDATE() , -- ApprovalDate - datetime
                  N'' , -- ApprovalOpinion - nvarchar(1000)
                  N''  -- ApprovalUserCode - nvarchar(50)
                )
    
    
    END

    也可以在触发器中调用接口

    CREATE TRIGGER decor
    ON dbo.SG_DecorationEntry 
    AFTER INSERT 
    AS 
    BEGIN
    
    declare @ServiceUrl as varchar(1000) 
    declare @UrlAddress varchar(500)
    --WebService地址:以http开头,结尾带斜杠,例如'http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/' 
    set @UrlAddress = '....'
    declare @FunName varchar(50)
    --WebService中调用的方法名:例如'getMobileCodeInfo'
    set @FunName = 'GetEntryAndExitData' 
    --以下参数对应WebService中4个参数的[参数名]
    declare @P1 varchar(100),@P2 varchar(100)
    set @P1 = 'data'
    set @P2 = 'userid'
    declare @P1_Value varchar(max),@P2_Value varchar(800)
    set @P1_Value = '{"OrganizationID": "BDA02110-39BF-48CE-8D00-E4D31A45EE88"}'
    set @P2_Value = ''
    set @ServiceUrl = @UrlAddress + @FunName + '?' + @P1 + '=' + @P1_Value 
    Declare @Object as Int
    Declare @ResponseText as Varchar(8000)
    
    Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
    Exec sp_OAMethod @Object, 'open', NULL, 'get',@ServiceUrl,'false'
    Exec sp_OAMethod @Object, 'send'
    Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
    
    Select @ResponseText 
    Exec sp_OADestroy @Object
    
    
    END
  • 相关阅读:
    MXNet--DMLC-Core代码解读与宏
    mxnet的训练过程——从python到C++
    L1正则化及其推导
    mshadow的原理--MXNet
    A-Softmax的总结及与L-Softmax的对比——SphereFace
    天猫-淘宝年货精选,内部特供,最高折扣,最优质量
    get_template_part() 函数详解备忘(转)
    (转)WordPress的主查询函数-query_posts()
    深度剖析WordPress主题结构(转)
    Science上发表的超赞聚类算法(转)
  • 原文地址:https://www.cnblogs.com/heyiping/p/11512961.html
Copyright © 2011-2022 走看看