Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
Performance Tuning
»
Sql Server Performance
Sql Server Performance
Rate Topic
Display Mode
Topic Options
Author
Message
suresh0534
suresh0534
Posted Wednesday, January 18, 2012 4:33 PM
SSC Rookie
Group: General Forum Members
Last Login: 2 days ago @ 1:55 AM
Points: 28,
Visits: 165
Hi,
If we create Temporay Tables in a Stored Procedure will degrade the performance of the query?
Ex:
CREATE TABLE #TempTable
(id int,name varchar(50))
INSERT INTO #TempTable
SELECT id,name FROM Employee
How to improve the performance of stored procedure while using temporary tables?
Thanks,
Suresh
Post #1238378
GilaMonster
GilaMonster
Posted Thursday, January 19, 2012 1:19 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 3:47 PM
Points: 38,096,
Visits: 30,391
suresh0534 (1/18/2012)
Hi,
If we create Temporay Tables in a Stored Procedure will degrade the performance of the query?
Maybe, or maybe it'll improve the performance due to been able to process smaller chunks of data. You should probably only use them when they do improve things
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 #1238492
TheSQLGuru
TheSQLGuru
Posted Friday, January 20, 2012 6:56 AM
Hall of Fame
Group: General Forum Members
Last Login: Today @ 3:22 PM
Points: 3,678,
Visits: 5,177
suresh0534 (1/18/2012)
Hi,
If we create Temporay Tables in a Stored Procedure will degrade the performance of the query?
Ex:
CREATE TABLE #TempTable
(id int,name varchar(50))
INSERT INTO #TempTable
SELECT id,name FROM Employee
How to improve the performance of stored procedure while using temporary tables?
Thanks,
Suresh
I have gotten 4+ orders of magnitude performance improvement by adding temporary table(s) to a stored procedure. I have also gotten 4+ orders of magnitude performance improvement by REMOVING temporary table(s) from a sproc. There is no right answer and doing this type of refactoring/tuning isn't something that can be covered in a few forum posts. Sorry...
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru at GMail
Post #1239419
deepkt
deepkt
Posted Friday, January 20, 2012 7:16 AM
SSC Veteran
Group: General Forum Members
Last Login: Friday, June 14, 2013 7:48 AM
Points: 202,
Visits: 289
Hi,
You can also use table variables for better performance but it has some limitations like,
1. Transaction logs are not recorded for the table variables. Hence, they are out of scope of the transaction mechanism
2. Any procedure with a temporary table cannot be pre-compiled, while an execution plan of procedures with table variables can be compiled in advance.
3. Table variables exist only in the same scope as variables
Post #1239437
GilaMonster
GilaMonster
Posted Friday, January 20, 2012 7:32 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 3:47 PM
Points: 38,096,
Visits: 30,391
deepkt (1/20/2012)
1. Transaction logs are not recorded for the table variables. Hence, they are out of scope of the transaction mechanism
Half true. They are out of transaction scope, but that does not mean that they are unlogged. They are logged like any other operations
2. Any procedure with a temporary table cannot be pre-compiled, while an execution plan of procedures with table variables can be compiled in advance.
Stored procedures are never pre-compiled. Execution plans are created on first execution only and remain until invalidated or removed from cache. In SQL 2000 temp tables did always cause recompiles, not the case in 2005 or above.
You also neglected to mention the severe performance implication (in a bad way) from the lack of statistics on table variables. They should be avoided if the correct costing of execution plans is even a consideration.
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 #1239450
Tempdb12
Tempdb12
Posted Monday, January 23, 2012 11:07 AM
Valued Member
Group: General Forum Members
Last Login: Thursday, May 09, 2013 11:43 AM
Points: 52,
Visits: 236
If you are doing a lot of Temp table operations. You can improve performance by moving the TempDB files to a different drive and Create multiple files as oppose to one.
This is not a direct answer but it will help on a large scale.
Post #1240351
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.