简体   繁体   中英

How do i make a constraint for this column

I want there to be a check constraint for the column hiredate. Here is my attempt and I only want the user to be able to enter a date greater than 01/01/1990.

ALTER TABLE EMP              
ADD CONSTRAINT HIRE_DATE_CK    
CHECK (HIREDATE >=1990/01/01)

This is the error im getting:

Comparison operator >= operands not compatible.

MySQL does not apply/have the check constraint. I'd recommend that you either manage the checks through front-end or follow Ronaldo's directions with two triggers: https://dba.stackexchange.com/questions/9662/check-constraint-does-not-work

The answer to this is to type 1990/1/1 within single quotes.

ALTER TABLE EMP
ADD CONSTRAINT HIRE_DATE_CK
CHECK (HIREDATE >='1990/01/01')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM