将行恢复为默认列值 mysql [英] revert rows to default column value mysql

查看:61
本文介绍了将行恢复为默认列值 mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 MySQL 社区服务器 5.1.有没有办法通过一个查询将所有行设置回它们的默认列值?

I am using MySQL community server 5.1. Is there a way to just set all the rows back to their default column values with one query?

我刚刚添加了很多行.我为大多数指定的列设置了默认值,但由于某种原因,所有列值都设置为 = 0.我想知道是否有一个查询可以将所有列值设置为其默认值,而且我也需要 where 子句的能力.

I just added a lot of rows. I had default values for most of the columns specified, but for some reason all the columns values were set = 0 instead. I was wondering if there is a query to set all the column values to their default value, and I would need the ability for a where clause too.

例如:

update table set values = values(default) where id > 300;

谢谢!

推荐答案

在 INSERT 和 UPDATE 查询中有一个可用的 DEFAULT 关键字,您可以使用它代替任何实际的列值:

There is a DEFAULT keyword available in INSERT and UPDATE queries which you can use in place of any real column value:

update my_table set my_column = DEFAULT where id > 300;

在 MySQL 手册中

注意还有一个 DEFAULT() 函数,如之前的回答中所述;您可以选择使用任何列的默认值.

Note that there is also a DEFAULT() function, as mentioned in a previous answer; with which you can select any column's default value for use.

这篇关于将行恢复为默认列值 mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆