Dùng CREATE TABLE ... LIKE sao chép cấu trúc.
Cú pháp:
CREATE TABLE yourTableName2 LIKE yourTableName1;
Tạo bảng Employee, chèn 3 bản ghi.
Tạo bảng mới:
mysql> create table StudentModifyTableDemo Like Employee; Query OK, 0 rows affected (0.50 sec)
Kiểm tra cấu trúc:
mysql> desc StudentModifyTableDemo;
Kết quả giống hệt Employee.
Copy dữ liệu:
mysql> insert into StudentModifyTableDemo select *from Employee; Query OK, 3 rows affected (0.16 sec) Records: 3 Duplicates: 0 Warnings: 0
Kiểm tra dữ liệu:
+------------+--------------+ | EmployeeId | EmployeeName | +------------+--------------+ | 1 | Carol | | 2 | John | | 3 | Johnson | +------------+--------------+ 3 rows in set (0.00 sec)