Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 8:53 AM
Points: 3,976, Visits: 2,990
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: Yesterday @ 8:24 AM
Points: 12,887, Visits: 31,835
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
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: Tuesday, July 15, 2014 6:01 AM
Points: 61, Visits: 276
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