Friday, July 22, 2011

Duplicating MySQL table to another table

Method #1: [the better option]

  1. get the creation table information of the table to be duplicated
  2. change the table name
  3. execute the script

Method #2: this will remove the index definitions of the table though. Use:

CREATE TABLE <newtable>  SELECT * FROM <oldtable> WHERE 1 = 0;

the where clause just says you are ONLY copying the structure and not the data.

Method #3: Copy to and from another database

  1. Copy the table to another database[#2]
  2. Rename the table on the other database[#2]
  3. Copy back to the source database[#1]


1 comment:

  1. MS-SQL version of Method 2:

    select *
    into [new table]
    from [old table]
    where 1 = 0