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 123»»»

PURPOSE OF TEMPORARY TABLES Expand / Collapse
Author
Message
Posted Friday, February 11, 2011 4:35 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, April 14, 2011 5:36 AM
Points: 30, Visits: 63
what are the main purposes for which temporary tables are used?
I want to know the uses of temporary tables in practical and commercial applications i.e. practically in working softwares.
Post #1062468
Posted Friday, February 11, 2011 5:38 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 11:19 AM
Points: 43,002, Visits: 36,158
Temporary storage of interim result sets that will be further processed by the procedure.


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1062491
Posted Friday, February 11, 2011 5:56 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 1:13 AM
Points: 1,532, Visits: 2,577
SQLCHILD (2/11/2011)
what are the main purposes for which temporary tables are used?
I want to know the uses of temporary tables in practical and commercial applications i.e. practically in working softwares.


Temporary tables are used if you want to hold data temporarily for certain processos to be done on that.

Post #1062499
Posted Friday, February 11, 2011 7:46 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, August 27, 2014 7:01 AM
Points: 177, Visits: 357
Also keep in mind SQL Server will use temp tables without you ever explicitly knowing about it.
Post #1062604
Posted Saturday, February 12, 2011 10:11 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 10:48 AM
Points: 37,075, Visits: 31,631
SQLCHILD (2/11/2011)
what are the main purposes for which temporary tables are used?


To go along with what Gail said above...

When used properly do "Divide'n'Conquer" a large "problem", you can get absolutely mind boggling blinding speed out of some queries. Seriously. Way too many people think that "good set based code" has to be a single query to accomplish a task and nothing could be further from the truth. I've used Temp Tables to divide up queries that have dozens of joins (typically created by an ORM or someone using a query designer) and that previous took anywhere from 45 minutes to 2 hours to run and have gotten them to run in seconds.

There are DBA's that won't allow Temp Tables to be used by developed code. It sometimes takes a bit to convince them that T-SQL will build "Work" tables in Temp DB behind the scenes but they normally come around when you show them that properly used Temp Tables can convert long running, resource greedy code that takes (sometimes) hours to run into something that takes only 3 or 4 seconds to run.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1062993
Posted Sunday, February 13, 2011 9:46 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, April 14, 2011 5:36 AM
Points: 30, Visits: 63
Dear Jeff Sir,

Thanks a lot for your reply, i also wanted to know that how do temporary tables hold the result set of a stored procedure. i have read about temporary tables uses and found that they are used to hold the result set of a stored procedure.
Please can you explain this with an example?
Post #1063262
Posted Sunday, February 13, 2011 9:46 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, April 14, 2011 5:36 AM
Points: 30, Visits: 63
Dear Sir,

Thanks a lot for your reply, i also wanted to know that how do temporary tables hold the result set of a stored procedure. i have read about temporary tables uses and found that they are used to hold the result set of a stored procedure.
Please can you explain this with an example?
Post #1063263
Posted Sunday, February 13, 2011 9:47 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, April 14, 2011 5:36 AM
Points: 30, Visits: 63
Dear Joy Sir,

Thanks a lot for your reply, i also wanted to know that how do temporary tables hold the result set of a stored procedure. i have read about temporary tables uses and found that they are used to hold the result set of a stored procedure.
Please can you explain this with an example?
Post #1063264
Posted Sunday, February 13, 2011 10:34 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 11:19 AM
Points: 43,002, Visits: 36,158
They can be, but it's the same principal. Store the results in a temp table for further processing. Nothing much fancier than that.

CREATE TABLE #StoredProcOutput (
<definition>
);

INSERT INTO #StoredProcOutput
EXEC SomeStoredProcedure



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1063280
Posted Sunday, February 13, 2011 11:07 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 10:48 AM
Points: 37,075, Visits: 31,631
SQLCHILD (2/13/2011)
Dear Jeff Sir,

Thanks a lot for your reply, i also wanted to know that how do temporary tables hold the result set of a stored procedure. i have read about temporary tables uses and found that they are used to hold the result set of a stored procedure.
Please can you explain this with an example?


Gail covered it above.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1063292
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse