由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 请教sql server temptable # 和 ##
相关主题
Sql Server有没有清除过期记录的有效办法?Should replicated tables be in the same data?
面试回来发考题2Oracle 9i collection join regular tables
求教:Oracle trigger 中生成的数据如何送到stored procedure中?请教sql server 2005,怎样在固定时间run stores procedure
In MySQL, 如何在procedure里create trigger?谢谢了?怎么样提高SQL SERVER的编程水平?
请各位帮我看看这个最简单的Stored Procedure (转载)请教有关junior level的database support的面试
什么数据库中文支持比较好啊SQL Server table variable 的一个问题请教。
sql server 面试题 (6)请教oracle select top 10 from ... order by desc
如何让SQL 2005 CLR Trigger返回结果给Stored Procedure用?真服了老印
相关话题的讨论汇总
话题: table话题: server话题: sql话题: stored话题: exists
进入Database版参与讨论
1 (共1页)
n********6
发帖数: 1511
1
Both can be used for temp table as a staging table. In user created stored
procedures, when and why do you use #table and ##table? What do you consider
in making a choice?
In my understanding,
##table exists until the server restart.
#table exists within the life cycle of the stored procedure.
Since in the end of the stored procedure the staging table (# and/or ##)
will be dropped, what makes the difference in choosing # or ##?
p*******d
发帖数: 359
2
好像#是local,##是global.
我也没用过##.不知道啥时候用.有人讲讲?

consider

【在 n********6 的大作中提到】
: Both can be used for temp table as a staging table. In user created stored
: procedures, when and why do you use #table and ##table? What do you consider
: in making a choice?
: In my understanding,
: ##table exists until the server restart.
: #table exists within the life cycle of the stored procedure.
: Since in the end of the stored procedure the staging table (# and/or ##)
: will be dropped, what makes the difference in choosing # or ##?

c*****d
发帖数: 6045
3
copy from sql doc
The two types of temporary tables, local and global, differ from each other
in their names, their visibility, and their availability.
Local temporary tables have a single number sign (#) as the first character
of their names; they are visible only to the current connection for the user
; and they are deleted when the user disconnects from instances of Microsoft
® SQL Server™ 2000.
Global temporary tables have two number signs (##) as the first characters
of their nam
c*****d
发帖数: 6045
4
对于local temp table很好理解
对于global temp table,可以被所有的用户访问没问题
但是这句话"they are deleted when all users referencing the table disconnect
from SQL Server",我觉得有问题
我做的试验(1,2...6,7是步骤)
1. A session
create table ##demo
2. B session (could be same or different user from A)
select * from ##test -- table exists
3. C session (could be same or different user from A)
insert into ##test -- table exists
4. B session
select * from ##test -- table exists and could see new row
5. close A session
6. B session
select * fr

【在 c*****d 的大作中提到】
: copy from sql doc
: The two types of temporary tables, local and global, differ from each other
: in their names, their visibility, and their availability.
: Local temporary tables have a single number sign (#) as the first character
: of their names; they are visible only to the current connection for the user
: ; and they are deleted when the user disconnects from instances of Microsoft
: ® SQL Server™ 2000.
: Global temporary tables have two number signs (##) as the first characters
: of their nam

n********6
发帖数: 1511
5
我都用过,用于stored procedure,然后作为scheduled job。都是按照以下步骤:
IF OBJECT_ID ('tempdb..##table')>0 -- 如果#就不需要。
DROP TABLE ##table -- 如果#就不需要。
step1: load data to # or ##,
step2: clean/process,
step3: load to final table/destination.
step4: drop ##table -- 如果#就不需要。
但是我不知道两种用法有何利弊。在实际应用中哪些情况下推荐用#,哪些情况下推荐
用##。
p*******d
发帖数: 359
6
我是能不用global就不用,有人讲讲打个比方啥时候该用这个。

disconnect

【在 c*****d 的大作中提到】
: 对于local temp table很好理解
: 对于global temp table,可以被所有的用户访问没问题
: 但是这句话"they are deleted when all users referencing the table disconnect
: from SQL Server",我觉得有问题
: 我做的试验(1,2...6,7是步骤)
: 1. A session
: create table ##demo
: 2. B session (could be same or different user from A)
: select * from ##test -- table exists
: 3. C session (could be same or different user from A)

1 (共1页)
进入Database版参与讨论
相关主题
真服了老印请各位帮我看看这个最简单的Stored Procedure (转载)
Any SSIS high hand here?什么数据库中文支持比较好啊
SQL中NOT EXIST和NOT IN有什么区别?sql server 面试题 (6)
Is there a limitation of the length of the table name?如何让SQL 2005 CLR Trigger返回结果给Stored Procedure用?
Sql Server有没有清除过期记录的有效办法?Should replicated tables be in the same data?
面试回来发考题2Oracle 9i collection join regular tables
求教:Oracle trigger 中生成的数据如何送到stored procedure中?请教sql server 2005,怎样在固定时间run stores procedure
In MySQL, 如何在procedure里create trigger?谢谢了?怎么样提高SQL SERVER的编程水平?
相关话题的讨论汇总
话题: table话题: server话题: sql话题: stored话题: exists