MYSQL - 更新整个列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7056450/
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:51:12  来源:igfitidea点击:

MYSQL - Update an entire Column

mysql

提问by Adam

I wanted to ask if there is a way to update an entire column with the same value. I want to run '0' down a column or '1'. I can use a php loop to do it but it will involve multiple DB calls etc.

我想问一下是否有办法用相同的值更新整个列。我想在列中运行“0”或“1”。我可以使用 php 循环来做到这一点,但它会涉及多个数据库调用等。

Hopeing for a SQL statement that can run the same value down an entire mysql column.

希望可以在整个 mysql 列中运行相同值的 SQL 语句。

cheers

干杯

回答by ChrisW

Something a simple as UPDATE table1 SET column1=1;should do it.

UPDATE table1 SET column1=1;应该做的事情很简单。

回答by H6.

UPDATE table_name SET column_name = 0

this will set the column value to 0 for all records, if this it want you want.

如果需要,这会将所有记录的列值设置为 0。

回答by fatnjazzy

if you want to subtract:

如果你想减去:

update table set col=col-1

or just update

或者只是更新

update table set col=0

without any where clause

没有任何 where 子句