简体   繁体   English

如何创建所有列都不为空的MySQL表?

[英]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.

相关问题 当HTML表单字段之一提交为空白(其中所有询问列的默认值为NULL)时,如何更新现有的MySQL表? - How to update existing MySQL table when one of the HTML form field is submitted blank where default value for all asked columns is NULL? 在MySQL 5.7中使用NULL时间戳列创建表 - Create table with NULL timestamp columns in MySQL 5.7 MySQL:如何将表中的所有列插入到新表中,而对于不匹配的额外列如何插入NULL? - MySQL: How to insert all columns from table to new table and NULL for extra columns not matched? 如何在mysql中删除该表的所有列均为空的表中的列。 我有38GB的表,因此需要性能。 - How to delete columns of a table in mysql where all values are null for that column. I have 38GB table so performance is required. MySQL 哪里不是所有的 NULL? - MySQL Where IS NOT ALL NULL? MYSQL-将所有列的默认值设置为NULL,而未设置默认值 - MYSQL - set default as NULL to all columns, where default is not set MySQL计数两列相同且不为空,同一表的地方 - MySQL Count Where Two Columns are Same and Not Null, Same Table 如何在mysql中创建表,其中表中的字段数等于php中excel文件中的列数? - How to create a table in mysql where the number of fields in the table equals the number of columns in the excel file in php? 如何创建 MySQL 表的备份,其中原始表具有其中一列的“设置”数据类型? - How to create a backup of a MySQL table where the original table has a "set" data type for one of the columns? 如何在MySQL中为此表的表和列创建同义词? - How to create synonym for table and columns of this table in MySQL?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM