zoukankan      html  css  js  c++  java
  • Sql临时表

    alter proc WorkInfo
     
    as
     begin transaction
      
      if exists(select * from TestTable1 where Stu_Status = 0) --检索表1中新增数据,默认新增状态为0
       begin
        select * into #temp from TestTable1 where Stu_Status = 0 --将新增数据写如一临时表中

        --select * from #temp --查看临时表数据

        insert into pubs.dbo.TestTable2 select Stu_Name,Stu_Sex,Stu_Age,Stu_Status from #temp --将临时表数据写如表2中
      
        --select * from pubs.dbo.TestTable2 --查看表2数据 

        update TestTable1 set Stu_Status = 1 where Stu_ID in (select Stu_ID from #temp)--更新表1中数据status=1
      
        --select * from TestTable1--查看表1数据

        --update TestTable1 set Stu_Status = 0 where Stu_ID in (select Stu_ID from TestTable1)--将表1数据更改为初始值status=0
      
        drop table #temp  --删除临时表
       end
      else
       select * from pubs.dbo.TestTable2 

     commit transaction
      return 1
     rollback transaction
      return 2

    GO

  • 相关阅读:
    图解表连接
    python 开发学习
    学习路线
    前端开发学习路径(完整版)
    JSON.parse()与JSON.stringify()的区别
    npm介绍和使用
    jQ
    BOM
    javaScript 内置对象-Array数组
    Ajax
  • 原文地址:https://www.cnblogs.com/VirtualMJ/p/515402.html
Copyright © 2011-2022 走看看