Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 537889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:58:28+00:00 2026-05-13T09:58:28+00:00

Bounty open: Ok people, the boss needs an answer and I need a pay

  • 0

Bounty open:
Ok people, the boss needs an answer and I need a pay rise. It doesn’t seem to be a cold caching issue.

UPDATE:

I’ve followed the advice below to no avail. How ever the client statistics threw up an interesting set of number.

#temp vs @temp

Number of INSERT, DELETE and UPDATE statements
0 vs 1

Rows affected by INSERT, DELETE, or UPDATE statements
0 vs 7647

Number of SELECT statements
0 vs 0

Rows returned by SELECT statements
0 vs 0

Number of transactions
0 vs 1

The most interesting being the number of rows affected and the number of transactions. To remind you, the queries below return identical results set, just into different styles of tables.


The following query are basicaly doing the same thing. They both select a set of results (about 7000) and populate this into either a temp or var table. In my mind the var table @temp should be created and populated quicker than the temp table #temp however the var table in the first example takes 1min 15sec to execute where as the temp table in the second example takes 16 seconds.

Can anyone offer an explanation?

declare @temp table ( 
id uniqueidentifier, 
brand nvarchar(255), 
field nvarchar(255),
date datetime, 
lang nvarchar(5), 
dtype varchar(50)
)
insert into @temp (id, brand, field, date, lang, dtype )
select id, brand, field, date, lang, dtype
from view 
where brand = 'myBrand' 
-- takes 1:15

vs

select id, brand, field, date, lang, dtype
into #temp
from view 
where brand = 'myBrand'

DROP TABLE #temp
-- takes 16 seconds
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:58:28+00:00Added an answer on May 13, 2026 at 9:58 am

    I believe this almost completely comes down to table variable vs. temp table performance.

    Table variables are optimized for having exactly one row. When the query optimizer chooses an execution plan, it does it on the (often false) assumption that that the table variable only has a single row.

    I can’t find a good source for this, but it is at least mentioned here:

    http://technet.microsoft.com/en-us/magazine/2007.11.sqlquery.aspx

    Other related sources:

    http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=125052

    http://databases.aspfaq.com/database/should-i-use-a-temp-table-or-a-table-variable.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Bounty update : Already got a very good answer from Mark. Adapted := into
Question Updated for Bounty In Flash I need to load a dynamically generated XML
I'd really appreciate an answer to this, but can't afford a bounty (!). Here
[answer auto-selected by bounty system against my will] I'm using subclipse, and always when
Bounty This question raises several issues. The bounty will go to an answer which
I had some troubles implementing Lawler's algorithm but thanks to SO and a bounty
Just to keep things interesting and close my final open question, the solution that
I'm currently playing with a bar chart implemented through Open Flash Charts (I believe
I need to reduce the file size of a color scan. Up to now
Heroku does not seem to be loading config/locales/pt.yml . (Language is being set correctly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.