Trying to prohibit writing zero values ​​in the datetime field

ALTER TABLE test ADD CONSTRAINT chk_dt CHECK (UNIX_TIMESTAMP(dt) != 0) 

Does not work. Table already created

  • Unfortunately and will not. MySQL does not support check only for compatibility with other databases can not swear on the syntax - Mike

1 answer 1

Clause is parsed but ignored by all storage engines.

Documentation

You can try to organize the required check in the trigger format.