create
proc Aa
@age int
as
if object_id('tempdb.dbo.##test')is null ////////////**** 判断临时表是否存在,存在就跳过,不存在就执行下面代码 ****/////////////
begin
create table tempdb.dbo.##test
@age int
as
if object_id('tempdb.dbo.##test')is null ////////////**** 判断临时表是否存在,存在就跳过,不存在就执行下面代码 ****/////////////
begin
create table tempdb.dbo.##test
(
age int not null,
num int not null
)
insert into ##test values(1,1)
end
else
begin
update ##testset age=@age
end
go
----------------------------------------
age int not null,
num int not null
)
insert into ##test values(1,1)
end
else
begin
update ##testset age=@age
end
go
----------------------------------------
create
proc getTest
as
select * from ##test
----------------------------------------
as
select * from ##test
----------------------------------------
本文介绍了一个使用 SQL 创建临时表并结合存储过程进行数据更新和检索的例子。该存储过程首先检查临时表是否存在,若不存在则创建并插入初始数据;若已存在,则更新表中的数据。另外还提供了一个用于获取临时表中所有记录的存储过程。
602

被折叠的 条评论
为什么被折叠?



