添加具有默认值的新SQL列 [英] Adding a new SQL column with a default value

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

问题描述

我正在寻找将列添加到默认值为0的MySQL数据库的语法

I am looking for the syntax to add a column to a MySQL database with a default value of 0

参考

推荐答案

尝试一下:

ALTER TABLE table1 ADD COLUMN foo INT DEFAULT 0;


从您链接到的文档中:


From the documentation that you linked to:

ALTER [ONLINE | OFFLINE] [IGNORE] TABLE tbl_name
   alter_specification [, alter_specification] ...

alter_specification:
    ...
    ADD [COLUMN] (col_name column_definition,...)
    ...

要找到column_definition的语法,请在页面下方搜索:

To find the syntax for column_definition search a bit further down the page:

column_definition子句对ADD和CHANGE使用与CREATE TABLE相同的语法.参见第12.1.17节创建表语法".

在链接页面中:

column_definition:  
   data_type [NOT NULL | NULL] [DEFAULT default_value]
   [AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY]  
   [COMMENT 'string']  
   [COLUMN_FORMAT {FIXED|DYNAMIC|DEFAULT}]  
   [STORAGE {DISK|MEMORY|DEFAULT}]  
   [reference_definition]  

请注意那里的DEFAULT这个词.

Notice the word DEFAULT there.

这篇关于添加具有默认值的新SQL列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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