如何在MySql中更改列默认值 [英] How to change column default value in MySql
本文介绍了如何在MySql中更改列默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用MySql5.5.
I am using MySql5.5.
我有一个表media__gallery
,我想将列default_format
的默认值从'NO'
更改为'YES'
,但是当我编写查询并通过命令行运行时,没有任何更新.
I have a table media__gallery
and I want change the default value of the column default_format
from 'NO'
to 'YES'
, but when I write the query and run through command line nothing is updated.
我的查询:
ALTER TABLE `media__gallery` CHANGE `default_format` `default_format` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_bin NULL DEFAULT 'YES';
MySql表:
mysql> desc media__gallery;
+----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | NULL | |
| context | varchar(64) | NO | | NULL | |
| default_format | varchar(255) | NO | | NULL | |
| enabled | tinyint(1) | NO | | NULL | |
| updated_at | datetime | NO | | NULL | |
| created_at | datetime | NO | | NULL | |
| category_id | int(11) | YES | UNI | NULL | |
+----------------+--------------+------+-----+---------+----------------+
我在这里想念什么?
推荐答案
ALTER TABLE media_gallery
ALTER COLUMN default_format SET DEFAULT 'YES'
这应该可以解决问题.
有关详细信息,请在此处(W3Schools-SQL DEFAULT约束)中查找.
Look here (W3Schools - SQL DEFAULT constraint) for more information .
这篇关于如何在MySql中更改列默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文