Friday, May 18, 2018

How do you copy old table to new table within same database?

Problem statement: How do you copy Old table TO New table with whole structures (column name, data type, datatype size, constraints) within the same database !

Syntax:

CREATE TABLE new_table LIKE old_table

e.g.
mysql>show tables;
------------------
tables in my db|
------------------
old_emp

mysql> CREATE TABLE new_emp LIKE old_emp;
QUERY OK, 0 rows affected(0.33sec)

verify:
mysql>show tables;
------------------
tables in my db|
------------------
old_emp
new_emp
------------------

No comments:

Post a Comment

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...