zoukankan      html  css  js  c++  java
  • sql server output用法说明

    带有output的insert语句.

    @@identity只能返回当前会话最后生产的标识列.  如果一次性插入多条语句的话. 需要返回这些自动生产的标识列. 那么outpu就派上用场了.

    declare @temp table(k int, v nvarchar(200))
    insert into t1(datacol)
    output inserted.keycol, inserted.datacol
    into @temp
    select * from @temp

    --------------------

    insert into DownLog
    output
    newid(),inserted.id,inserted.ID,inserted.ID, inserted.ID,getdate() into MatchOrderLog
    values('123444','aaaaaa.txt',getdate(),1,1,1)

    select  * from  MatchOrderLog

     

    带有output的delete语句和update语句也大同小异.

    delete语句能操作deleted临时表. 而update的本质是delete和insert一次能操作inserted和updated两张表.

    
    

    update loanee set MatchOrder=@MatchOrder,UpdateTime=getdate()

    output
    newid(),deleted.id,deleted.ApplicationID,deleted.MatchOrder, inserted.MatchOrder,getdate() into MatchOrderLog
    where ApplicationID=@ApplicationID and DeleteState=0 and LoaneeType=0

    ============================

    deleted.参数名  是更改前的参数值

    inserted.参数名  是更改或者插入后的参数值 

    使用 格式    :    insert into  表名      output    inserted.参数名,inserted.参数名2    into  记录表     values(表值,表值2,表值3...)

              update   表名  set  参数名=参数值,参数名2=参数值2 ...     output    inserted.参数名,inserted.参数名2    into  记录表     where  条件...

     
  • 相关阅读:
    ATS项目更新(1) CC视图与备份路径同步
    IP地址的正则表达式
    python下载图片(2)
    NS2网络模拟(2)丢包率
    NS2网络模拟(7)homework03.tcl
    python 教程 第二十二章、 其它应用
    python 教程 第十九章、 图形界面编程
    python中string的操作函数
    python中对文件、文件夹的操作
    HTTP状态码(HTTP Status Code)
  • 原文地址:https://www.cnblogs.com/yangjinwang/p/4809639.html
Copyright © 2011-2022 走看看