flen flen -4 years ago 72
MySQL Question

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)?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download