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


Usage of Temprory Table in Stored Procedure


Usage of Temprory Table in Stored Procedure

Author
Message
sivaramakrishnan G
sivaramakrishnan G
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 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.




Regards
Siva
Bill Talada
Bill Talada
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2926 Visits: 2125
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.
Eugene Elutin
Eugene Elutin
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12448 Visits: 5478
[quote
Is more usage of Temprory table degrade the performance.
...
[/quote]

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!":-D
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
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