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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值