June 5, 2011 at 8:23 pm
I even notice ppl using ## or ###, does this have another meaning?
Is this a common good practice? Or is there other specific good reasons we are using these hexes.
Thanks!
cino
June 5, 2011 at 8:57 pm
cino (6/5/2011)
I even notice ppl using ## or ###, does this have another meaning?Is this a common good practice? Or is there other specific good reasons we are using these hexes.
Thanks!
cino
A temp table with a single #sign has limited scope..it exists only for your connection, and only until your connection terminates...a #temp table inside a procedure only exists inside the procedure, and is dropped after the proc completes.
two # signs, like ##Temp, make the table available to all other connections...a global temp table. that table can stick around after your connection is dropped, but is destroyed when all connections on the server disconnect.
more than two # signs is just taking advantage of the fact that the # sign is a valid character for table names...nothing special beyond that. it's a global temp table with extra # in it's name.
best practice is to use single #temp tables, unless you have a specific reason to make data available in a global temp table, but still don't need a permanent table.
Lowell
June 6, 2011 at 4:52 am
Just be careful with global temp tables: as soon as the connection that created it goes away, the global temp table will go away also (as soon as all other connections are on a statement that doesn't use it).
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
June 6, 2011 at 5:31 am
cino (6/5/2011)
I even notice ppl using ## or ###, does this have another meaning?Is this a common good practice? Or is there other specific good reasons we are using these hexes.
Thanks!
cino
Using # or ## prefix in temp table name is SQL syntax. There is no alternative to this.
Using ### is bad practice. It confuses the reader (as it did to you)
June 6, 2011 at 6:39 am
The other thing to be aware of with global temp tables is not just that they can go away, but also that you can end up with errors if you don't realize one has not yet gone away.
You can get DDL errors when you try to create one that already exists. Even worse, you can get data messed up because you don't realize two or more processes are accessing the same global temp table.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply