The usage and difference of select into from and insert into select

Both select into from and insert into select are used to copy tables. The main difference between the two is: select into from requires that the target table does not exist, because it will be automatically created when inserting. insert into select from requires the target table to exist


Backup table data: create table emp as select * from scott.emp

Restore table data: insert into emp select * from scott.emp


1. Copy the table structure and its data:

create table table_name_new as select * from table_name_old

2. Copy only the table structure:

create table table_name_new as select * from table_name_old where 1=2;

or:

create table table_name_new like table_name_old

3. Copy only table data:

If the two tables have the same structure:

insert into table_name_new select * from table_name_old

If the two tables have different structures:

insert into table_name_new(column1,column2...) select column1,column2... from table_name_old

pasting







http://www.studyofnet.com/news/182.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325524560&siteId=291194637