Copying Columns into one table to another in MSSQL

Discussion in 'Databases' started by RedDem0n, Oct 28, 2009.

  1. #1
    I am trying to find out what the QUERY in MSSQL is to make an exact copy of a table under a different name but for all of it's columns to be transferred as well as anything else that it has. Not including the rows.

    Keep in mind Listings2 has no columns created in it, so it would have Listing1's columns copied over to it.

    So

    Listings1 - TableName
    Name Email State - Columns

    Copied to another table named Listings2

    Listings2 - Table Name
    Name Email State - Columns
     
    RedDem0n, Oct 28, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    INSERT INTO new_table SELECT * FROM old_table;

    You may need to specify column names...

    INSERT INTO new_table (column_names) SELECT (column_names) FROM old_table;
     
    jestep, Oct 28, 2009 IP