Search code examples
mysqldatatablesrdbms

How to create a table similar to another table without copying the data at creation?


I have a table books, I want to create table Book101 and then copy the contents of table books into it.


Solution

  • CREATE TABLE Book101 AS SELECT * FROM books WHERE 1=0;
    

    Above example will create only structure.

    If you want to Clone the table with structure and data both then you can you below one:

    CREATE TABLE Book101 AS SELECT * FROM books;