Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Copy structure of a Table with data and without data

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 82
    Comment on it

    To copy structure in MySQL with data you need to execute the following MySQL statements:

    use dbname;
    create table new_table_name
    select * from existing_table_name;
    

    If you require the copy of structure without data then you need to execute the following MySQL Statements:

    use dbname;
    create table new_table_name
    select * from existing_table_name where 1=0;
    

    But the above MySQL statements copy the structure without indexes and constraints. To copy the structure with indexes and constraints you need to execute the following MySQL Statements:

    CREATE TABLE `new_table_name` LIKE `existing_table_name`;
    

    The above statement only create the copy of the structure of table with indexes and constraints but not the data. To copy the data with structure(with indexes and constraints) you need to execute following MySQL statements:

    CREATE TABLE `new_table_name` LIKE `existing_table_name`;
    INSERT INTO `new_table_name` SELECT * FROM `existing_table_name`;
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: