SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


PURPOSE OF TEMPORARY TABLES


PURPOSE OF TEMPORARY TABLES

Author
Message
SQLCHILD
SQLCHILD
Valued Member
Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)

Group: General Forum Members
Points: 70 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.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)

Group: General Forum Members
Points: 118157 Visits: 45534
Temporary storage of interim result sets that will be further processed by the procedure.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
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


Joy Smith San
Joy Smith San
SSCarpal Tunnel
SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)

Group: General Forum Members
Points: 4022 Visits: 3200
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.
Henry Treftz
Henry Treftz
SSC-Addicted
SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)SSC-Addicted (437 reputation)

Group: General Forum Members
Points: 437 Visits: 365
Also keep in mind SQL Server will use temp tables without you ever explicitly knowing about it.
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)

Group: General Forum Members
Points: 118129 Visits: 41471
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
SQLCHILD
SQLCHILD
Valued Member
Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)

Group: General Forum Members
Points: 70 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?
SQLCHILD
SQLCHILD
Valued Member
Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)

Group: General Forum Members
Points: 70 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?
SQLCHILD
SQLCHILD
Valued Member
Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)

Group: General Forum Members
Points: 70 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?
GilaMonster
GilaMonster
SSC Guru
SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)

Group: General Forum Members
Points: 118157 Visits: 45534
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, MVP, M.Sc (Comp Sci)
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


Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)SSC Guru (118K reputation)

Group: General Forum Members
Points: 118129 Visits: 41471
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search