Create table in MySQL that matches another table?

后端 未结 4 820
鱼传尺愫
鱼传尺愫 2020-12-07 16:33

I am using MySQL. I have a table called EMP, and now I need create one more table (EMP_TWO) with same schema, same columns, and same constraints. How can I do this?

4条回答
  •  再見小時候
    2020-12-07 16:43

    Why don't you go like this

    CREATE TABLE new_table LIKE Select * from Old_Table;   
    

    or You can go by filtering data like this

    CREATE TABLE new_table LIKE Select column1, column2, column3 from Old_Table where column1 = Value1;   
    

    For having Same constraint in your new table first you will have to create schema then you should go for data for schema creation

    CREATE TABLE new_table LIKE Some_other_Table;
    

提交回复
热议问题