0

I want to create table with date_of_birth column and use check() function to only allow adults to be inserted in. All i try causes: "curdate() cannot be used in CHECH() clause"

One of I've tried adding in CREATE TABLE:

CONSTRAINT `adultcheck` CHECK ( TIMESTAMPDIFF(YEAR, date_birth, CURDATE())  >= 21)
  • I think its duplicate of https://stackoverflow.com/questions/2981930/mysql-trigger-to-prevent-insert-under-certain-conditions – cosmos Nov 29 '17 at 09:39

1 Answers1

0

Check constraints aren't supported. You can write them, but they are ignored. Have a look in the manual: https://dev.mysql.com/doc/refman/5.7/en/create-table.html

  • CHECK

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

Solution is to deal with it in your application.

Community
  • 1
  • 1
fancyPants
  • 50,732
  • 33
  • 89
  • 96