1

Trying to create a table with sql but getting error of "A symbol name was expected! A reserved keyword can not be used as a column name without backquotes".

Create TABLE Tour (  
    Tour_ID int AUTO_INCREMENT,  
    Tour_Title VARCHAR(15) Not NULL,  
    Cost decimal(4,2) DEFAULT '2000.00',   
    CONSTRAINT tour_pk PRIMARY KEY (Tour_ID),  
    CONSTRAINT Ck_cost CHECK Cost BETWEEN 1500 and 2500  
    );

Error is on the CHECK statement so i don't know why the error of reserved keyword is showing. Looked everywhere so hopefully not asking a stupid question.

Ivar
  • 6,138
  • 12
  • 49
  • 61

1 Answers1

1

MySQL does not implement check constraints, so there is no utility to including them. However, it should be parsing them correctly.

I think you are missing parentheses:

Create TABLE Tour (  
    Tour_ID int AUTO_INCREMENT,  
    Tour_Title VARCHAR(15) Not NULL,  
    Cost decimal(4,2) DEFAULT '2000.00',   
    CONSTRAINT tour_pk PRIMARY KEY (Tour_ID),  
    CONSTRAINT Ck_cost CHECK (Cost BETWEEN 1500 and 2500) 
);

I should emphasize that if you actually want to implement the check, you need to do so in your application or using a trigger.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786