• PiMané (9/4/2013)


    Just one more thing, probably a "stupid" question but here it goes anyway 😉

    Temp tables created with SELECT .. INTO #temp FROM ... and then create clustered index ... on #temp (id) and create index ... on #temp (...) is slower than CREATE TABLE #temp (....) ... and then the INSERT INTO #temp SELECT ... FROM?

    And are the statistics on both methods the same?

    Thanks,

    Pedro

    Two general options:

    1) The table and indexes are created, then the data is loaded

    2) The data goes in, then the indexes go on

    The second choice is likely to have better statistics. Likely, not definitely (as in 100%). Creating an index results in a full scan for statistics where as adding data to existing indexes you're subject to the auto update processes and sampled updates by default.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning