Home > Mysql > How to copy a table structure and data

How to copy a table structure and data


To copy table structure run this query

CREATE TABLE database_name.`new_table_name` LIKE database_name.`old_table_name` ;

To copy table data run this query

INSERT INTO database_name.`new_table_name` SELECT * FROM database_name.`old_table_name` ;

Advertisements
  1. November 15, 2011 at 5:24 pm

    Hello! interesting site! I’m really like it! Very, very good!

  2. November 21, 2011 at 10:39 pm

    Thanks a ton for taking a few minutes to line this all out for people. This write-up ended up being quite helpful if you ask me.

  3. December 24, 2012 at 12:50 pm

    Wow, this really helped me, I was looking on Stackoverflow, all the answers were rude and they did not work.

  4. Tabla
    January 7, 2013 at 9:38 am

    While this works perfectly fine for structure and data, I am wondering if there would be a way to copy triggers along, too.

    Do you see a chance?

    • viswanath
      February 12, 2013 at 9:17 am

      Thanks you this query is perfectly working.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: