Home Forums SQL Server 2005 SQL Server 2005 General Discussion Is it "better" to specify the definition of a temporary table, or just define it on the fly? RE: Is it "better" to specify the definition of a temporary table, or just define it on the fly?

  • There's a small confusion.

    INSERT INTO, won't create a table, SELECT INTO will. Example:

    --This will create a table

    SELECT column1, column2, column3

    INTO #TempTable

    FROM MyTable

    --This won't

    INSERT INTO #TempTable

    SELECT column1, column2, column3

    FROM MyTable

    Now, to answer the question. IMHO, It depends. If you don't care on the structure of your table and need something easy, you can use SELECT INTO. However, creating the table before inserting data will give you more flexibility and control on it's structure.

    What happens if you need more columns than the ones that you'll have available in the select? What happens if you want an exact copy of the columns used in a query?

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2