Main content of this article:
update update, batch batch update
insert data into the table, and insert the data in the table Insert into another table
insert ignore ignore duplicate data insertion error problem
set sql_safe_updates=0;# 常规updateupdate springdemo.users set pwd=nickname where id=id;
The following is an example of batch update based on conditions in stack overflow: assign the field with id=1 to apple, assign the value of id=2 to orange,
assign the value of id=3 to peach
Basic insert example:
INSERT INTO tb_name(col1, col2) VALUES ("hyq","M");# 例如insert into teacher(name, age) values('jack ma', 32);
Work , often we have to insert data from one table into another table:
INSERT INTO tb_al_sample (biz_id,sample_path) SELECT 3,FILE FROM idcard_image WHERE FILE IS NOT NULL;
When there is a unique index in the table, if If you insert the same value, mysql will report an error, so we generally use the following form:
insert ignore into tb_name (title, introduction) VALUES (%s, %s)
to avoid the program exiting directly.
The above is the detailed content of Detailed explanation of commonly used updates and inserts in mysql. For more information, please follow other related articles on the PHP Chinese website!