INSERT (Version 2.0)
Updated at:
Copy as MD
Syntax
INSERT [IGNORE]
INTO table_name
[( column_name [, ...] )]
[VALUES]
[(value_list[, ...])]
[query];Parameters
- IGNORE: optional. If the primary key of a new record is the same as that of an existing record, the new record is discarded.
- column_name: optional. The name of the column.
- query: inserts all records queried from another table to this table.
Examples
- Insert a record into the CUSTOMER table:
INSERT INTO customer(customer_id,customer_name,phone_num,city_name,sex,id_number,home_address,office_address,age,login_time) values (002367,'Yang Guo','13900001234','Hangzhou',0,'987300','West Lake','Zhuantang, Hangzhou Cloud Town',23,'2018-03-02 10:00:00'); - Insert multiple records into the CUSTOMER table:
INSERT INTO customer(customer_id,customer_name,phone_num,city_name,sex,id_number,home_address,office_address,age,login_time) values (002367,'Li Si','13900001111','Hangzhou',0,'987300','West Lake','Zhuantang, Hangzhou Cloud Town',23,'2018-03-02 10:00:00'), (002368,'Zhang San','13900002222','Hangzhou',0,'987300','West Lake','Zhuantang, Hangzhou Cloud Town',28,'2018-08-01 11:00:00'), (002369,'Wang Wu','13900003333','Hangzhou',1,'987300','West Lake','Zhuantang, Hangzhou Cloud Town',35,'2018-09-12 08:11:00'); - Insert multiple records into the CUSTOMER table without specifying column names:
INSERT INTO customer values(002367,'Tom','13900001111','Hangzhou',0,'987300','West Lake','Hangzhou Cloud Town',23,'2018-03-02 10:00:00'),(002368,'Alex','13900002222','Hangzhou',0,'987300','West Lake','Hangzhou Cloud Town',28,'2018-08-01 11:00:00'),(002369,'Eric','13900003333','Hangzhou',1,'987300','West Lake','Hangzhou Cloud Town',35,'2018-09-12 08:11:00'); - For examples of INSERT query statements, see INSERT SELECT FROM (Version 2.0).
Precautions
- If you do not specify column names, the values to be inserted must follow the sequence declared in the CREATE TABLE statement.
- The INSERT statement supports the following functions: CURDATE, SYSDATE, and LOCALTIME/LOCALTIMESTAMP/NOW.
Is this page helpful?