mysql copy & modify table

1. Copy the table structure to the new table newadmin. (The data in the table will not be copied) -

CREATE TABLE newadmin LIKE admin;

2. The following statement will copy the data to the new table.
Note: This statement is actually just a table of the results of the select statement. Therefore, the newadmin table will not have a primary key or index.

CREATE TABLE newadmin AS (SELECT * FROM admin);
CREATE TABLE newadmin AS (SELECT username, password FROM admin);

3. If you want to actually copy a table. You can use the following statement.

CREATE TABLE newadmin LIKE admin;   
INSERT INTO newadmin SELECT * FROM admin;

4 , update, update according to other records

update portal_menu2 a,portal_menu b 
set b.MENU_CONTENT=a.MENU_CONTENT 
where b.CMEMBER_CODE='S000107' and a.MENU_ID=b.menu_id and a.menu_id='2490';

Guess you like

Origin blog.csdn.net/fangye1/article/details/110952803