How to create a Temp Table?

  • I would Like to create a temporary table to store data to do some testing. How can I create a temp table? How do I go about doing it?

    Thanks.

  • ummmm,

    Create Table #tablename(

    ......

    )



    Clear Sky SQL
    My Blog[/url]

  • Temporary Tables

    You can create local and global temporary tables. Local temporary tables are visible only in the current session, and global temporary tables are visible to all sessions. Temporary tables cannot be partitioned.

    Prefix local temporary table names with single number sign (#table_name), and prefix global temporary table names with a double number sign (##table_name).

    SQL statements reference the temporary table by using the value specified for table_name in the CREATE TABLE statement, for example:

    CREATE TABLE #MyTempTable (cola INT PRIMARY KEY);

    INSERT INTO #MyTempTable VALUES (1);

    --------------------------------------------------------------------------------------
    [highlight]Recommended Articles on How to help us help you and[/highlight]
    [highlight]solve commonly asked questions[/highlight]

    Forum Etiquette: How to post data/code on a forum to get the best help by Jeff Moden[/url]
    Managing Transaction Logs by Gail Shaw[/url]
    How to post Performance problems by Gail Shaw[/url]
    Help, my database is corrupt. Now what? by Gail Shaw[/url]

  • Or to create a temp table pre populated with data from existing table

    select col1, col2

    into #temp

    from table1

  • zy-eliz (10/14/2009)


    I would Like to create a temporary table to store data to do some testing. How can I create a temp table? How do I go about doing it?

    Thanks.

    You can populate a temp table directly from a permanent table just using...

    SELECT * INTO #country FROM [COUNTRY]

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply