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 909517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:53:27+00:00 2026-05-15T16:53:27+00:00

I have some sprocs that need a temp table. In order not to hardcode

  • 0

I have some sprocs that need a temp table. In order not to hardcode the column types (which are varchar with some length) so I don’t have to change the declarations when the reference table schema changes (i.e. fields become longer) I do this (instead of a create table call):

select orderId
into #sometmptbl
from orders
where 1=2

However, when you do a showplan on this it actually seems to be going to the table/index:

QUERY PLAN FOR STATEMENT 1 (at line
1).

STEP 1
    The type of query is CREATE TABLE.

STEP 2
    The type of query is INSERT.
    The update mode is direct.

    FROM TABLE
        orders
    Nested iteration.
    Index : orders_idx1
    Forward scan.
    Positioning at index start.
    Index contains all needed columns. Base table will not be read.
    Using I/O Size 2 Kbytes for index leaf pages.
    With LRU Buffer Replacement Strategy for index leaf pages.
    TO TABLE
        #sometmptbl
    Using I/O Size 2 Kbytes for data pages.

Total estimated I/O cost for statement
1 (at line 1): 632082.

Does this mean 1=2 gets evaluated for every entry in the index? Is there a way to do this in a constant time?

Update:

Here’s the actual I/O cost after the execute so it looks like the actual reads are indeed 0 so there’s no performance impact:

Table: orders scan count 0, logical reads: (regular=0 apf=0 total=0), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: #sometmptbl_____00002860018595346 scan count 0, logical reads: (regular=1 apf=0 total=1), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Total actual I/O cost for this command: 2.
Total writes for this command: 3
0 row(s) affected.
  • 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-15T16:53:28+00:00Added an answer on May 15, 2026 at 4:53 pm

    If you set statistics io on, you should see zero logical and physical reads.
    It may create a plan to scan the index, but it appears not to actually use it.

    I would recommend NOT creating temp tables this way in a high volume production environment. There are system table locking issues, as well as a slight performance hit (your mileage may vary). (also the identity attribute of a column gets carried over into the temp table).

    As a shortcut – I do the 1=2 into an explicit tempdb..MyScratchTable, and then use RapidSQL (or some other tool), to generate the DDL from that scratch table.

    If its a varchar, there shouldn’t be any reason why you can’t standardize the column length on the max value and just use that everwhere.

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

Sidebar

Ask A Question

Stats

  • Questions 466k
  • Answers 466k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The AALayer in your log message makes me think that… May 16, 2026 at 1:45 am
  • Editorial Team
    Editorial Team added an answer I'm guessing you want the feedback functionality. May 16, 2026 at 1:45 am
  • Editorial Team
    Editorial Team added an answer TL;DR #!/bin/bash cd "$(dirname "$0")" The long winded explanation How… May 16, 2026 at 1:45 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.