Copy table without copying data

CREATE TABLE foo SELECT * FROM bar

copies the table foo and duplicates it as a new table called bar.

How can I copy the schema of foo to a new table called bar without copying over the data as well?


Solution 1:

Try

CREATE TABLE foo LIKE bar;

so the keys and indexes are copied over as, well.

Documentation

Solution 2:

Try:

CREATE TABLE foo SELECT * FROM bar LIMIT 0

Or:

CREATE TABLE foo SELECT * FROM bar WHERE 1=0