What are the common methods of inserting data in sql
This article mainly explains "what are the common methods of sql inserting data". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the common methods of sql inserting data?"
The copy code is as follows:
INSERT INTO table1 (id, name, address) VALUES (1, ygl, 'beijing') is suitable 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
Let's briefly talk about the third sentence here. Because you can specify the columns to be inserted into the talbe2 and get the data source through relatively complex query statements, it may be more flexible to use, but we must also note that when we specify the columns of the target table, we must fill in all the non-empty columns, otherwise we will not be able to insert the data. When we write it in the following abbreviated format:
The copy code is as follows:
INSERT INTO table2 SELECT id, name, address FROM table1
At this point, if we omit the columns of the target table, all the columns of the target table will be inserted by default, and the order of the columns after SELECT must be exactly the same as the definition order of the columns in the target table in order to complete the correct data insertion, which is easy to be ignored and should be noted.
Thank you for your reading, these are the contents of "what are the common methods of sql inserting data?" after the study of this article, I believe you have a deeper understanding of what the common methods of sql inserting data have, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!