SQL insertion statements are one of the most common SQL statements, and the following will introduce you to the three most common SQL insertion statements for your reference.
When we insert data into the database, the commonly used SQL insertion statements are as follows:
INSERT INTO table1(id, name, address) VALUES(1, ygl, 'beijing') - for T-sql and PL/SQL;
SELECT id, name, address INTO table2 FROM table1 - automatically create table2, T-sql usage;
INSERT INTO table2(id, name, address) SELECT id, name, address FROM table1
Here is a brief explanation of the third SQL insertion statement, because the columns inserted into talbe2 can be specified, and the data source can be obtained through relatively complex query statements, it may be more flexible to use, but we must also pay attention to the fact that when we specify the columns of the target table, we must fill in all non-empty columns, otherwise data insertion will not be possible.
INSERT INTO table2 SELECT id, name, address FROM table1
At this time, if we omit the columns of the target table, all columns in the target table will be inserted by default, and the order of the columns after SELECT must be exactly the same as the defined order of the columns in the target table to complete the correct data insertion, which is easy to overlook and is worth noting. |