如何在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 .