[英]How to create a MySQL table where all columns are NOT NULL?
I'm creating a table where I have no use for the NULL value. 我正在创建一个表,其中我没有使用NULL值。 Therefore, all my columns are NOT NULL. 因此,我所有的列都不为空。 This is how I create it: 这是我创建它的方式:
CREATE TABLE example (
id INT UNSIGNED NOT NULL,
column1 TEXT NOT NULL,
column2 VARCHAR(100) NOT NULL,
column3 TIMESTAMP NOT NULL,
...
Do I really have to write NOT NULL all the time? 我真的必须一直都写NOT NULL吗? Or is there a way to prevent NULL columns to be inserted (by mistake)? 还是有一种方法可以防止插入NULL列(错误)?
Existing SQL specification does not support NOT NULL for a complete table. 现有的SQL规范不支持完整表的NOT NULL 。 See Specification . 参见规格 。 Even MySQL 5.5 documentation clearly states that NOT NULL can be applied to column. 甚至MySQL 5.5文档也明确指出可以将NOT NULL应用于列。 So it can not be applied to table. 因此它不能应用于表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.