|
|
How to create duplicate table? - Mysql
|
Views : 1040
|
|
Tagged in : Mysql
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
You can create a duplicate table by copying an existing mysql table to a new table.
Syntax:
CREATE TABLE table_name2 LIKE table_name1;
INSERT table_name2 SELECT * FROM table_name1;
>> The first command creates the new table table_name2 by duplicating the structure of the existing table table_name1.
>> The second command copies the data from old(table_name1) to new(table_name2).
Creating a duplicate table helps when you use same table name in subquery.
Example:
mysql> update test set date1=DATE_ADD(date1, interval 1 MONTH) where
id IN (select id from test as df where id like '1%');
I have got an error,
ERROR 1093 (HY000): You can't specify target table 'test' for update in FROM clause
Here i have created a duplicate table test1 and used the query as,
mysql> update test set date1=DATE_ADD(date1, interval 1 MONTH) where id IN (select id from test1 as df where id like '1%');
|
|
By - Sanju, On - 2008-07-29 |
|
|
|