Home > Database > Mysql Tutorial > Detailed explanation of commonly used updates and inserts in mysql

Detailed explanation of commonly used updates and inserts in mysql

黄舟
Release: 2017-09-26 11:20:30
Original
2923 people have browsed it

Main content of this article:

  1. update update, batch batch update

  2. insert data into the table, and insert the data in the table Insert into another table

  3. insert ignore ignore duplicate data insertion error problem


update update, batch batch update


set sql_safe_updates=0;# 常规updateupdate springdemo.users set pwd=nickname where id=id;
Copy after login

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

Detailed explanation of commonly used updates and inserts in mysql

insert data into the table, insert data from the table into another table


Basic insert example:

INSERT INTO tb_name(col1, col2) VALUES ("hyq","M");# 例如insert into teacher(name, age) values('jack ma', 32);
Copy after login

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;
Copy after login

insert ignore ignore duplicate data insertion error problem


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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template