SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 Temp Tables in SQL Server
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

benildusmuerling
Yak Posting Veteran

Australia
81 Posts

Posted - 06/22/2012 :  01:25:22  Show Profile  Reply with Quote
Hi All,

Geeks thanks for reading my post, can anyone tell me which temp tables are good to use, in response to the increase in performance.

would it be the temp tables called the table variables starting with '@' or other temp tables called the #temptables

Thanks,

AB

sunitabeck
Flowing Fount of Yak Knowledge

5152 Posts

Posted - 06/22/2012 :  07:27:35  Show Profile  Reply with Quote
The ones that start with @ are TABLE VARIABLEs and the ones that start with # (or ##) are TEMP TABLES. You will see a lot of articles that discuss the pluses and minuses of each in-depth if you google using that terminology.

To start with, temp tables can be indexed, table variables cannot. Temp tables cannot be used in UDFs, table variables can be. etc. etc. etc.

Edit: I didn't read the original post carefully, or I would not have replied!!
quote:
Geeks thanks for reading my post

Edited by - sunitabeck on 06/22/2012 07:31:16
Go to Top of Page

benildusmuerling
Yak Posting Veteran

Australia
81 Posts

Posted - 06/25/2012 :  21:08:02  Show Profile  Reply with Quote
Thanks for the comment..reallyhelpful
Go to Top of Page

xhostx
Constraint Violating Yak Guru

USA
261 Posts

Posted - 06/27/2012 :  11:49:18  Show Profile  Reply with Quote
quote:
Originally posted by benildusmuerling

Hi All,

Geeks thanks for reading my post, can anyone tell me which temp tables are good to use, in response to the increase in performance.

would it be the temp tables called the table variables starting with '@' or other temp tables called the #temptables

Thanks,

AB



It is always up too what your needs are. I just want to add something to what sunitabeck said; you can still use a physical table during the run time of your script and you can call it a temporary table.

defined Temporary tables you usally find them in tempdb like any other database instance in SQL Server.

Luck,

--------------------------
Get rich or die trying
--------------------------
Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 06/27/2012 :  11:59:05  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
As a general rule - use temp tables for large things, table variables for small things.

Often it's easier to develop larger processes using temp tables as they persist and you can follow the data through the statements.
For smaller processes it's easier to use table variables as you don't have to keep droppping the temp tables.

Usually it's only important to differentiate if you are running things many times a minute.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.41 seconds. Powered By: Snitz Forums 2000