SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


What is # in first letter of table names?


What is # in first letter of table names?

Author
Message
Ed Wagner
Ed Wagner
SSC-Forever
SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)

Group: General Forum Members
Points: 46033 Visits: 10844
A good programming practice is to always drop your temporary stuff in the procedure when you're done. I know they're supposed to be destroyed when the session terminates, but I sometimes see shrapnel left over when people don't drop them.

Dropping them also makes developing your procedures easier because you can't create them if they already exist. Knowing that they're local to my session, I still like to use the following approach before creating a temp table.

IF OBJECT_ID('tempdb.dbo.#temp_table', 'U') IS NOT NULL DROP TABLE #temp_table;




Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Lowell
Lowell
SSC Guru
SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)

Group: General Forum Members
Points: 68970 Visits: 40915
Ed Wagner (7/9/2013)
A good programming practice is to always drop your temporary stuff in the procedure when you're done. I know they're supposed to be destroyed when the session terminates, but I sometimes see shrapnel left over when people don't drop them.

Dropping them also makes developing your procedures easier because you can't create them if they already exist. Knowing that they're local to my session, I still like to use the following approach before creating a temp table.

IF OBJECT_ID('tempdb.dbo.#temp_table', 'U') IS NOT NULL DROP TABLE #temp_table;



interestingly, there's quite a few threads here, where it's shows that if you explicitly drop tables at the end of your procedure, you incur a slight performance cost over letting SQL destroy the tables automatically.

now if you are creating a script, i 100% agree,bullet proof your code and drop them before you (re-)create them, just in case.

Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
masoudk1990
masoudk1990
SSC Veteran
SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)

Group: General Forum Members
Points: 228 Visits: 299
Alan.B (7/9/2013)
HanShi mentioned local and global temp tables. You don't see this as often but a global temp table has two numbers signs in front of it like so: ##temptable.

To get some understanding about the difference between the two, open a new query window in SSMS and run these SELECT statements:


CREATE TABLE #LocalTempTable (xId int); --(1) Local Temp Table
CREATE TABLE ##GlobalTempTable (xId int); --(2) Global Temp Table

INSERT INTO #LocalTempTable VALUES(1);
INSERT INTO ##GlobalTempTable VALUES(1);



Then, in the same query window, you could successfully run these queries:


SELECT * FROM ##GlobalTempTable
SELECT * FROM #LocalTempTable



If you open a new query window, however, and run the two SELECT statements above, the first will be successful but the second one will fail.


Much appreciated, very good example

___________________________________
Computer Enterprise Masoud Keshavarz
I don't care about hell.
If I go there I've played enough Diablo to know how to fight my way out.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search