This article is a mirror article of machine translation, please click here to jump to the original article.

View: 22021|Reply: 1

[Source] There are three common SQL insertion statements

[Copy link]
Posted on 2/4/2015 1:08:07 PM | | |

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.




Previous:Google Gmail 5 million passwords leaked and downloaded
Next:Add characters in bulk before each line in a txt text file
Posted on 2/24/2021 3:55:02 PM |
SQLServer imports data from one table to another
https://www.itsvse.com/thread-8931-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com