|
|
|
SSC 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.
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 2:24 PM
Points: 37,716,
Visits: 29,971
|
|
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
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 3:16 AM
Points: 1,370,
Visits: 2,291
|
|
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.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, May 06, 2013 1:51 PM
Points: 175,
Visits: 327
|
|
| Also keep in mind SQL Server will use temp tables without you ever explicitly knowing about it.
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 2:32 PM
Points: 32,906,
Visits: 26,792
|
|
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."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|
|
SSC 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?
|
|
|
|
|
SSC 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?
|
|
|
|
|
SSC 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?
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 2:24 PM
Points: 37,716,
Visits: 29,971
|
|
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
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 2:32 PM
Points: 32,906,
Visits: 26,792
|
|
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."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|