MySQL-如何修改列的默认值? [英] MySQL - How to modify column default value?

查看:95
本文介绍了MySQL-如何修改列的默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将列的默认值从无"更改为其他值?例如,如果我在创建该行时未指定日期,则希望我的日期的默认值是0000-00-00.

How do I change my column's default value from None to something else? For example, I want my dates to have a default value of 0000-00-00 if I don't specify one when I create the row.

我在phpMyAdmin中理解了这一点,但是我不确定如何通过命令提示符来做到这一点.

I understand this in phpMyAdmin, but I'm not sure how to do it via command prompt.

我也了解添加列时的操作方法.但是我所有的列都是经过制作的,并且其中一些包含数据.

I also understand how to do this when adding a column. But all of my columns are made and have data in some of them.

ALTER TABLE table1 ADD COLUMN foo INT DEFAULT 0;

通过搜索,我找到了这一行,但是我不确定这是否是我想要的吗?

From searching, I found this line, but I'm not sure if that's what I want?

ALTER TABLE foobar_data MODIFY COLUMN col VARCHAR(255) NOT NULL DEFAULT '{}';

推荐答案

使用 ALTER TABLE 更改修改 默认列的值.检查此链接 ALTER TABLE SYNTAX (更改表语法)

Use ALTER TABLE to CHANGE or MODIFY the DEFAULT value of column. Check this link ALTER TABLE SYNTAX

ALTER TABLE `tableName` CHANGE `columnName` `columnName` DATE DEFAULT '0000-00-00'; 
ALTER TABLE `tableName` MODIFY `columnName` DATE DEFAULT '0000-00-00'; 

这篇关于MySQL-如何修改列的默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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