Mysql – How to prevent the creation of Mysql columns with default values that are not defined

MySQL

Is there a Mysql server setting that will prevent the creation of columns that are NOT NULL but do not have a default value specified?

I'm trying to prevent the creation of fields like this:

ALTER TABLE mytable ADD mydate DATE NOT NULL;

I know I can prevent INSERTs by setting sql_mode=STRICT_ALL_TABLES, but I want to prevent the creation of the columns in the first place.

Best Answer

I don't think there is such an option. You could request such at bugs.mysql.com.

I disagree with making NULL (or, for that matter) NOT NULL mandatory. NULL and NOT NULL have important uses in schema design and execution. PRIMARY KEYs must be NOT NULL, and that is implicitly provided. Due to business logic, some columns should not be left out; some should be allowed to be optional.

NULL has a lot of different semantics, and arbitrarily forcing all columns to be NULL begs the issue of which semantics you want. Examples: Optional (product specifications); not yet provided (an end_date); unknown (due to partial data received).