Home > database >  How to define number columns with CHECK constraints in MySQL database
How to define number columns with CHECK constraints in MySQL database

Time:12-14

SQL Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'number, hofYear number(4) CHECK (hofYear BETWEEN 1901 AND 2155), hofSeries VAR' at line 22

Code:

CREATE TABLE mospo_HallOfFame( 
    hofdriverId number,
    hofYear number(4) CHECK (hofYear BETWEEN 1901 AND 2155),
    hofSeries VARCHAR2(50) NOT NULL CHECK (hofSeries IN ('BritishGT','Formula1','FormulaE','SuperGT')),

CodePudding user response:

Try:

CREATE TABLE mospo_HallOfFame( 
  hofdriverId INTEGER, 
  hofYear INTEGER CHECK (hofYear BETWEEN 1901 AND 2155), 
  hofSeries VARCHAR(50) NOT NULL CHECK (hofSeries IN ('BritishGT','Formula1','FormulaE','SuperGT')));

This changes the data types to INTEGERs and a VARCHAR.

  • Related