CREATE TABLE `test` (
`id` INT(10) UNSIGNED NOT NULL,
`c1` VARCHAR(60) NULL DEFAULT NULL,
`c2` VARCHAR(60) NOT NULL,
PRIMARY KEY (`id`)
)
In the information_schema.columns.COLUMN_DEFAULT contains NULL for both c1,c2 columns but c2 doesn’t have default value.
How to get the real COLUMN_DEFAULT value?
In
information_schema.columns, ifCOLUMN_DEFAULTisNULLandIS_NULLABLEisNOthen it doesn’t have a default.But basically you can see it as: the default, if not specified, is always
NULL. So,c2isn’t allowed to beNULL, but it will default toNULL, thus will always need to be specified on insert statements.Note: a field specified as
NOT NULLdoesn’t need to be able to representNULL, thus it can theoretically take up (slightly) less space.