在 MySQL 中创建表时如何定义列的默认值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5810538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to define the default values for a column when creating tables in MySQL?
提问by swisscheese
What is the SQL to define DEFAULT
values in MySQL?
DEFAULT
在 MySQL 中定义值的 SQL 是什么?
In the code below what needs to be added / changed to give IsObsolete a default value of N
?
在下面的代码中,需要添加/更改什么才能为 IsObsolete 提供默认值N
?
CREATE TABLE Team
(
TeamId CHAR(16) NOT NULL,
DateCreated TIMESTAMP NOT NULL,
IsObsolete CHAR(1) NOT NULL DEFAULT N,
UpdateTime TIMESTAMP NOT NULL
);
采纳答案by Anthony Accioly
IsObsolete CHAR(1) NOT NULL DEFAULT 'N'
回答by CanSpice
You probably want to put quotes around it:
你可能想在它周围加上引号:
CREATE TABLE Team
(
TeamId CHAR(16) NOT NULL,
DateCreated TIMESTAMP NOT NULL,
IsObsolete CHAR(1) NOT NULL DEFAULT 'N',
UpdateTime TIMESTAMP NOT NULL
);
回答by MonoThreaded
If your are changing your structure via phpMyAdmin, you should just type in the char (e.g N) as opposed to 'N'
如果您通过 phpMyAdmin 更改您的结构,您应该只输入字符(例如 N)而不是“N”