更新 MySQL 中的一列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6503824/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:20:56  来源:igfitidea点击:

Update a column in MySQL

mysqlinsert-update

提问by Muleskinner

I have a table table1with three columns and a bunch of rows:

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

[key_col|col_a|col_b]

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

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

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


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


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

回答by Naveed

You have to use UPDATE instead of INSERT:

您必须使用 UPDATE 而不是 INSERT:

For Example:

例如:

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

回答by Chris Snowden

UPDATE table1 SET col_a = 'newvalue'

Add a WHEREcondition if you want to only update some of the rows.

WHERE如果您只想更新某些行,请添加条件。

回答by Abhay Shiro

This is what I did for bulk update:

这是我为批量更新所做的:

UPDATE tableName SET isDeleted = 1 where columnName in ('430903GW4j683537882','430903GW4j667075431','430903GW4j658444015')

回答by kairos

if you want to fill all the column:

如果要填充所有列:

update 'column' set 'info' where keyID!=0;

回答by piotrpo

If you want to update data you should use UPDATEcommand instead of INSERT

如果你想更新数据,你应该使用UPDATE命令而不是INSERT