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

How to run standalone mock server on local laptop

 Please download the standalone wiremock server from Direct download section at the bottom of the page.  Download and installation Feel fre...