将MySQL字段重置为默认值

时间:2021-12-14 17:10:23

Is there a command in MySQL to reset a field to its default value? You know, in favor of the "Do Not Repeat Yourself" rule, I don't want to write the (quite long) default value multiple times in code, only once in the DB.

MySQL中是否有命令将字段重置为其默认值?你知道,有利于“不要重复自己”规则,我不想在代码中多次写入(很长)默认值,只在DB中写一次。

I looked around quite some time in google, found nothing. I'm starting to suspect such command doesn't exist, but nevertheless, if it does, sy here's going to know about it. :)

我在谷歌相当一段时间环顾四周,一无所获。我开始怀疑这样的命令不存在,但是,如果确实如此,那么sy会知道它。 :)

1 个解决方案

#1


23  

MySQL has a DEFAULT keyword (and function) that will do exactly what you want.

MySQL有一个DEFAULT关键字(和函数),可以完全按照您的意愿执行。

UPDATE table SET col = DEFAULT WHERE id = 2

OR

要么

UPDATE table SET col = DEFAULT(col2) WHERE id = 3

#1


23  

MySQL has a DEFAULT keyword (and function) that will do exactly what you want.

MySQL有一个DEFAULT关键字(和函数),可以完全按照您的意愿执行。

UPDATE table SET col = DEFAULT WHERE id = 2

OR

要么

UPDATE table SET col = DEFAULT(col2) WHERE id = 3