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  条件...

     
  • 相关阅读:
    python 三方面库整理
    windows MYSQL 安装及修改root密码
    TCP 套叠字
    自动化谷歌浏览驱动
    python os
    python 协程
    python GIL :全局解释器
    python 多进程
    python 多线程
    python 3 往Excel 中的写入内容但不覆盖原内容
  • 原文地址:https://www.cnblogs.com/yangjinwang/p/4809639.html
Copyright © 2011-2022 走看看