locked
Creating tables from other tables RRS feed

  • Question

  • Hi,

    I have a table of data and would like to make an exact copy of the table (structure and data).

    Are there any ways to do this without having to first run a create statement (that would have been based on the original table being manually scripted) and then select insert for the data. The reason being that this initial table may change and that would mean I would have to go and change my create statements. It would be nice to have a blind command:-

    create table A based on table B

    etc

    Thanks

    Rhys

    Wednesday, March 22, 2006 12:09 AM

Answers

  • Rhys,

    The SELECT INTO command may work for you.

    here is an example

    CREATE Table B ( i int primary key )

    INSERT into B values(1)

    INSERT into B values(2)

    SELECT * INTO A from B -- this creates table A

    Karl Tarbet

    Wednesday, March 22, 2006 4:01 AM

All replies

  • Rhys,

    The SELECT INTO command may work for you.

    here is an example

    CREATE Table B ( i int primary key )

    INSERT into B values(1)

    INSERT into B values(2)

    SELECT * INTO A from B -- this creates table A

    Karl Tarbet

    Wednesday, March 22, 2006 4:01 AM
  • Thanks Karl, that was exactly what I was looking for.
    Wednesday, March 22, 2006 4:04 AM