更新 MySQL 中的一列

2021-11-20 00:00:00 mysql insert-update

我有一个包含三列和一堆行的表 table1:

I have a table table1 with three columns and a bunch of rows:

[key_col|col_a|col_b]

我想用一组值更新 col_a(即保持 col_b 不变),如下所示:

I want to update col_a with a set of values (i.e. leaving col_b unchanged), something like this:

INSERT INTO table1 AS t1 (key_col, col_a) VALUES ("k1", "foo"), ("k2", "bar");


但它不起作用,我该怎么做?


But it doesn't work, how do I do this?

推荐答案

你必须使用 UPDATE 而不是 INSERT:

You have to use UPDATE instead of INSERT:

  • 更新语法

例如:

UPDATE table1 SET col_a='k1', col_b='foo' WHERE key_col='1';
UPDATE table1 SET col_a='k2', col_b='bar' WHERE key_col='2';

相关文章