Home > Blockchain >  Can not insert data here and also can not delet the check constraint of this table
Can not insert data here and also can not delet the check constraint of this table

Time:12-19

I copy and paste this from a mysql examples query page but like that tittle say, i can't insert data or delete the check constraint of this table creaded query. So please i need an explanation of those 2 things, the insert data and the drop check constrait of this table, thanks.

CREATE TABLE IF NOT EXISTS job_history ( 
EMPLOYEE_ID decimal(6,0) NOT NULL, 
START_DATE date NOT NULL, 
END_DATE date NOT NULL
CHECK (END_DATE LIKE '--/--/----'), 
JOB_ID varchar(10) NOT NULL, 
DEPARTMENT_ID decimal(4,0) NOT NULL 
);

CodePudding user response:

Every index or constraint has a name; you need the name to remove it. If you don't provide one MySQL makes one up for you. Easiest way to see it is do:

show create table job_history

You will see the constraint is named something like job_history_chk_1. Remove it with:

alter table job_history drop constraint job_history_chk_1

fiddle

The constraint you have makes no sense; it says that END_DATE, when cast to a string, must match the pattern --/--/----. Since - and / are not like-operator metacharacters, that means it must be the exact string --/--/----. And a date type column will never be that. Whatever you were trying to do with that constraint needs to be done some completely different way, if indeed it is possible at all.

  • Related