A
A
Alesk892016-05-23 01:22:33
MySQL
Alesk89, 2016-05-23 01:22:33

How to implement (SQL) mass update of table cells with binding by row id?

There is a table with many columns (10). PRIMARY KEY - id
It is necessary to update the data in some columns by binding to id. Bulk, per request.
id should remain the same.
Googled and tried the query below.
Execution doesn't work

Affected rows: 0 Found rows: 0 Warnings: 0

INSERT INTO tab_copy (`id`, `dat`, `status`) VALUES (1, 'hf',2), (2,'2222',2), (3,'3333',2) ON DUPLICATE KEY
UPDATE `id`= VALUES(`id`)

How to bulk update data in a table in the most efficient way?
php mysql

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2016-05-23
@Alesk89

If `id` is PRIMARY KEY or UNIQUE, then it does not need to be changed upon collision.

... ON DUPLICATE KEY UPDATE `dat`= VALUES(`dat`), `status` = VALUES(`status`)

S
Sergey Savostin, 2016-05-23
@savostin

Update id = id
Without values.
Should work.
Also try replace instead of insert and without on duplicate...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question