Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Usage of Temprory Table in Stored Procedure Expand / Collapse
Posted Thursday, February 6, 2014 5:32 AM


Group: General Forum Members
Last Login: Wednesday, July 15, 2015 4:24 AM
Points: 14, Visits: 92
Dear All,
For my project salary calculation writtened in Stored Proceure based.There is nearly 50 stored Procedure to Calculate different kind of Calculations.Some of the Stored Proceure Temprory tables used to do intermediate calculation and finally pushed to maintable.
Is more usage of Temprory table degrade the performance.For the every used Temprory tables proper indexing done.We noticed that Temprory Database some pressure is there while executing the process.Can i convert the Temprory table to Static intermediate table.Kindly give your views.

Post #1538590
Posted Thursday, February 6, 2014 6:01 AM

Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: 2 days ago @ 12:42 PM
Points: 326, Visits: 1,767
You may create constraints and indexes on temporary tables. I think you would benefit by having a regular table; that way you could depend on constraints and indexes and possibly updated statistics always being there. There are global and local temp tables depending on a declaration like #tbl or ##tbl and the local ones are cleaned up when a connection is closed. I find that there is overhead in using global objects accessible outside of a connection. Temp tables cause contention in sysobjects which might be a problem if you are often creating and dropping them.

Table variables within a stored procedure perform very well if there are less than thousands of rows and they benefit from constraints.

You may need to play around with your unique situation to find out empirically what works best.
Post #1538606
Posted Thursday, February 6, 2014 6:41 AM


Group: General Forum Members
Last Login: Yesterday @ 8:21 AM
Points: 2,934, Visits: 5,478
Is more usage of Temprory table degrade the performance.

Any additonal line of code (excluding comments) degrades the performance less or more...
There is nothing wrong with using temp tables.
Using static (permanent) tables, global temp tables and/or table variables will not avoide using tempdb, which whould be properly managed by DBA's (yes queries using just and only permanent tables also might use tempdb).

"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1538627
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse