I have sprocs that need a temp table. In order not to recode the column types (which are varchar with a certain length), so I do not need to change the declarations when changing the link table schema (i.e. the fields become longer). I do this (instead of calling the create table):
select orderId
into #sometmptbl
from orders
where 1=2
However, when you do showplan on this, it actually looks like a table / index:
APPLICATION REQUEST PLAN 1 (on 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
Using I/O Size 2 Kbytes for data pages.
Total estimated I / O cost for operator 1 (line 1): 632082.
Does this mean that 1 = 2 is evaluated for each record in the index? Is there a way to do this for a constant time?
Update
- , , 0, :
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:
Total actual I/O cost for this command: 2.
Total writes for this command: 3
0 row(s) affected.