October 24, 2016
MySQL about constraint
J.Doe’s Question:
Good afternoon,
Can anyone tell me what’s wrong with my code on PHP MY ADMIN, I’m trying to write a CONSTRAINT and create values for the car color in the beginning ( with table creation)
CREATE TABLE T_CAR
(CAR_ID INTEGER NOT NULL PRIMARY KEY,
CAR_MARK CHAR(32) NOT NULL,
CAR_MODEL VARCHAR(16),
CAR_NUMBER CHAR(10) NOT NULL,
CAR_COLOR CHAR(16) CHECK (VALUE IN ('white', 'black', 'red', 'green', 'blue')))
The problem is with the last line (error message syntax not known).
Thanks in advance.
MySQL ignores check
expression.
Manual: Create Table
The CHECK clause is parsed but ignored by all storage engines.
Try Enum:
CREATE TABLE T_CAR (
CAR_ID INTEGER NOT NULL PRIMARY KEY,
CAR_MARK CHAR(32) NOT NULL,
CAR_MODEL VARCHAR(16),
CAR_NUMBER CHAR(10) NOT NULL,
CAR_COLOR ENUM('white', 'black', 'red', 'green', 'blue') NOT NULL
)