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?
Wouldn't it be
CREATE TABLE foo LIKE bar; so the keys and everything else but the data carries over as well?
SHOW CREATE TABLE bar; you will get a create statement for that table, edit the table name, or anything else you like, and then execute it.
This will allow you to copy the indexes and also manually tweak the table creation.
You can also run the query within a program.
CREATE TABLE new_table AS (SELECT * FROM old_table WHERE 0); different table copy scenarios are explained in this article How to copy a database table
This can also serve the purpose: CREATE TABLE foo LIKE bar
No comments:
Post a Comment