CREATE PROCEDURE a
@ga varchar(20)
as
begin
INSERT INTO ##table (PriKey, Description)
SELECT ForeignKey, Description
FROM SomeView where ForeignKey=@ga
endcreate proc b
as
begin
SELECT ForeignKey, Description into ##table FROM SomeView where 1=2
exec a 1000 --执行a
endselect * from ##table 不能使用#table,要用##table
@ga varchar(20)
as
begin
INSERT INTO ##table (PriKey, Description)
SELECT ForeignKey, Description
FROM SomeView where ForeignKey=@ga
endcreate proc b
as
begin
SELECT ForeignKey, Description into ##table FROM SomeView where 1=2
exec a 1000 --执行a
endselect * from ##table 不能使用#table,要用##table
AS
BEGIN
CREATE TABLE #gg
(prikey VARCHAR(10),description VARCHAR(32)) EXEC a 1000
END
2、全局临时表(##开头)对其它连接也有效,在当前连接和其他访问过它的连接都断开时自动删除。
3、不管局部临时表还是全局临时表,只要连接有访问权限,都可以用 drop table #Tmp(或者drop table ##Tmp)来显式删除临时表。
使用全局临时表需要加上##
if object_id('tempdb..##临时表') is not null
drop table ##临时表
else
create table ##临时表..