user5229419
user5229419

Reputation:

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.

Upvotes: 0

Views: 61

Answers (2)

Gamith Silva
Gamith Silva

Reputation: 11

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')

Upvotes: 1

zedfoxus
zedfoxus

Reputation: 37119

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

Upvotes: 1

Related Questions