MySQL: Check constraint with Date

后端 未结 3 1602
说谎
说谎 2021-01-20 00:16

I am using MySQL and here is a simple query set:

create table dcheck (
    fdate date,
    sdate date,
    check (fdate <= sdate)
);

insert          


        
3条回答
  •  佛祖请我去吃肉
    2021-01-20 00:34

    MySQL doesn't implement CHECK constraints. From the latest (5.6) fine manual:

    The CHECK clause is parsed but ignored by all storage engines.

    So the syntax is parsed for compatibility other other SQLs but the checking is not implemented.

    You could fake your CHECK constraint with BEFORE INSERT and BEFORE UPDATE triggers that threw an exception if the desired condition was not met.

提交回复
热议问题