This is just a quick recipe to copy a existing table to a new table in Mysql

Here is the syntax

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
    { LIKE old_tbl_name | (LIKE old_tbl_name) }

Example:

create table files_tmp like files;

The good part of it is it creats an identical table structure from old table, but no data.

So, adding data in this way.

INSERT [LOW_PRIORITY | HIGH_PRIORITY] [IGNORE]
    [INTO] tbl_name [(col_name,...)]
    SELECT ...
    [ ON DUPLICATE KEY UPDATE
      col_name=expr
        [, col_name=expr] ... ]

Example:

Insert files_tmp select * from files where size>1000000000;

 

 

Comments powered by CComment