Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

What is # in first letter of table names? Expand / Collapse
Author
Message
Posted Tuesday, July 9, 2013 8:29 AM
SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Saturday, July 23, 2016 7:13 AM
Points: 9,168, Visits: 8,479
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
Post #1471653
Posted Tuesday, July 9, 2013 9:16 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:22 AM
Points: 14,445, Visits: 37,857
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!
Post #1471694
Posted Tuesday, July 9, 2013 9:32 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Sunday, March 6, 2016 5:38 AM
Points: 66, 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.
Post #1471705
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse