Copy structure of MySQL tables without the data

3

In MySQL, can I copy the structure? of a table using this command:

CREATE TABLE foo SELECT * FROM bar LIMIT 0;

By doing this I will have a table foo with the same columns of the table bar , but in the table foo there will be no data.

But what about indexes, constraints, foreign keys? Are they copied too?

If they are not copied, how could I make an exact copy of my table bar without data, but have the same configuration as foo in terms of indexes, restrictions, etc?

    
asked by A. Cedano 18.08.2017 в 01:12
source

1 answer

3

One possibility would be:

CREATE TABLE IF NOT EXISTS foo LIKE bar;
    
answered by 18.08.2017 / 01:33
source