Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
SunnyDee
Yak Posting Veteran
79 Posts |
Posted - 2005-06-10 : 14:25:53
|
| Can someone please help me understand the advantages of temporary tables. I would think that if you are joining the same table multiple times through various queries in one stored procedure that I would have better results. The number of reads is down considerably, but it is taking longer. What are the general rules for temporary tables?Thanks |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-06-10 : 14:44:00
|
>>What are the general rules for temporary tables?temporary tables are permanent tables stored in tempdb database. Sql server drops the table when the session is over. Temp tables with the same name can co-exist for different sessions. You can create indexes, constraints etc for temp tables. Use temp tables when you need a place to hold data for just the life of a stored procedure instance or a QA window session. They can be useful to simplify complex statements by breaking the statement into smaller logical steps.I don't really understand your comment:quote: I would think that if you are joining the same table multiple times through various queries in one stored procedure that I would have better results. The number of reads is down considerably, but it is taking longer.
What are you trying to do?Be One with the OptimizerTG |
 |
|
|
vivek.kumargupta
Starting Member
45 Posts |
Posted - 2005-06-13 : 04:39:38
|
| I beleive temp tables are used to have the progamming leverage using SQL Server 2k.Else if the solution exists without using the temp table then it is wll and good .Howevertemp table is an overhead for the server.Pl confirm .Thanks, Vivek |
 |
|
|
bonbon
Starting Member
3 Posts |
Posted - 2005-07-21 : 04:12:22
|
| how cam i select from temp table ? i seached for that topic but i wrote that script but unfortunatly, it doesn't work. i don't know whyCREATE TABLE #TEMP (DOMAIN_NAME NVARCHAR(1024) , SITE_ID BIGINT) INSERT INTO #TEMP(DOMAIN_NAME ,SITE_ID)SELECT DOMAINS.DOMAIN_NAME ,CP_HOSTING.Site_id FROM CP_HOSTING, DOMAINS WHERE CP_HOSTING.DOMAIN_ID = DOMAINS.DOMAIN_ID AND CP_HOSTING.LRN2B_ID=@LRN2B_ID AND DOMAINS.domain_type <>2SELECT DOMAIN_NAME FROM #TEMP |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-07-21 : 04:41:55
|
| http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=52682MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|