Monday, December 27, 2021

How to copy a table using CTAS (create Table as Select from ) in MySQL

 

Syntax for CTAS:

create table  <db_name.table_name> as select * from <db_name.table_name> ;


mysql> create table test3.reports_bak as select * from reports;

--------------

create table test3.reports_bak as select * from reports

--------------


Query OK, 55 rows affected (0.04 sec)

Records: 55  Duplicates: 0  Warnings: 0


mysql> use test3;

Database changed

mysql> show tables;

--------------

show tables

--------------


+-----------------+

| Tables_in_test3 |

+-----------------+

| reports_bak     |

+-----------------+

1 row in set (0.00 sec)


No comments:

Post a Comment