How to copy a table in MySQL
MySQL database เราสามารถ copy table (โครงสร้างและข้อมูลต่างๆ) ได้ด้วยง่ายๆ ดังนี้
สมมติต้องการสร้าง table ชื่อ table_new มาใหม่ โดยให้มีโครงสร้างและข้อมูลจาก table ชื่อ table_name สามารถทำได้ดังนี้
1. Create copy table ใหม่ด้วยคำสั่ง
CREATE TABLE table_new LIKE table_name;
หลังจากรันคำสั่งด้านบนจะได้ table ที่มีโครงสร้างเหมือน table ต้นฉบับ
2. Copy data จาก original table ไปยัง new table
INSERT INTO table_new SELECT * FROM table_name;