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

Detailed explanation of commonly used updates and inserts in mysql

黄舟
黄舟Original
2017-09-26 11:20:302909browse

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;

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);

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;

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)

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!

Statement:
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