How can we add a constraint which enforces a column to have only positive values.
Tried the following mysql statement but it doesn\'t work
create tab
As of MySQL 8.0.16 (MariaDB 10.2.1), CHECK constraints are enforced. (In earlier versions constraint expressions were accepted in the syntax but ignored).
Therefore you can use:
CREATE TABLE test (
test_column INT CHECK (test_column > 0)
);
or
CREATE TABLE test (
test_column INT,
CONSTRAINT test_column_positive CHECK (test_column > 0)
);