简体   繁体   中英

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. 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? Or is there a way to prevent NULL columns to be inserted (by mistake)?

Existing SQL specification does not support NOT NULL for a complete table. See Specification . Even MySQL 5.5 documentation clearly states that NOT NULL can be applied to column. So it can not be applied to table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM