Difference between insert table and create table as, insertcreate

Source: Internet
Author: User

Difference between insert table and create table as, insertcreate

Author: iamlaosong

First, the biggest difference is that the two are different types of statements. The former is DML statements (data operation language, SQL processing data, and other operations collectively referred to as data operation language ), after the task is completed, it must be submitted to take effect. The latter is a DDL Statement (Data Definition Language, used to define and manage the languages of all objects in the SQL database). After the execution, it takes effect directly and does not provide rollback, high efficiency. Secondly, the functions are different. The former only inserts data and must be created first. The latter completes table creation and data insertion.

Insert into table1 (columns1, columns2.) select columns1, columns2-from table2;
Insert the query result from table2 to table1, provided that table1 and table2 already exist;
 
Create. as .. select generally has the following three methods:
1. create table table1 as select * from table2 where 1 = 2;
Create a table with the same structure as table2, and only copy the structure without copying data;
2. create table table1 as select * from table2;
Create a table with the same structure as table2, and copy the data at the same time;
3. create table table1 (columns_a, columns_ B) as select columns1, columns2-from table2;
Create a table with the same structure as table2. Copy the structure and copy data, but specify the column name of the new table. This format is also used to copy some fields of table 2;

If the following two formats follow the appropriate query conditions, you can copy the data that meets the conditions to the new table. For example:

Create table table1 as select * from table2 where columns1> = 1;

If possible, we recommend that you use the second method. This method not only creates tables and inserts data at a time, but also has high efficiency, especially when the copied data volume is large, this prevents a large amount of data from waiting for submission in the rollback space.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.