2012-12-21 11 views
12

Sto caricando i dati da un file CSV in una tabella temporanea di staging e questa tabella temporanea viene interrogata molto. Ho guardato il mio piano di esecuzione e ho visto che molto tempo è dedicato alla scansione del tavolo temporaneo.È possibile creare indici su una tabella temporanea quando si utilizza SELECT INTO?

C'è un modo per creare l'indice su questa tabella quando I SELECT INTO esso?

SELECT *  
FROM TradeTable.staging.Security s 
WHERE (
    s.Identifier IS NOT NULL 
    OR s.ConstituentTicker IS NOT NULL 
    OR s.CompositeTicker IS NOT NULL 
    OR s.CUSIP IS NOT NULL 
    OR s.ISIN IS NOT NULL 
    OR s.SEDOL IS NOT NULL 
    OR s.eSignalTicker IS NOT NULL) 

enter image description here

+0

@HamletHakobyan non è possibile creare un tabella e utilizzare select in per inserirvi. – HLGEM

+0

@HamletHakobyan È una tabella heap, quindi dovrei aggiungere una colonna per PK? –

+2

Hai provato a eseguire una dichiarazione indice come dichiarazione successiva nel batch? – HLGEM

risposta

17

La tabella creato da SELECT INTO è sempre un mucchio. Se si desidera una colonna PK/Identità è possibile fare come lei suggerisce nei commenti

CREATE TABLE #T 
(
Id INT IDENTITY(1,1) PRIMARY KEY, 
/*Other Columns*/ 
) 

INSERT INTO #T 
SELECT * 
FROM TradeTable.staging.Security 

o evitare l'esplicito CREATE e la necessità di elencare tutte le colonne con

SELECT TOP (0) IDENTITY(int,1,1) As Id, * 
INTO #T 
FROM TradeTable.staging.Security 

ALTER TABLE #T ADD PRIMARY KEY(Id) 

INSERT INTO #T 
SELECT * 
FROM TradeTable.staging.Security 
Problemi correlati