简体   繁体   English

我如何对此列进行约束

[英]How do i make a constraint for this column

I want there to be a check constraint for the column hiredate. 我希望对列hiratedate有一个检查约束。 Here is my attempt and I only want the user to be able to enter a date greater than 01/01/1990. 这是我的尝试,我只希望用户输入的日期大于1990年1月1日。

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. MySQL不应用/没有check约束。 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 我建议您要么通过前端管理检查,要么通过两个触发器遵循Ronaldo的指示: https : //dba.stackexchange.com/questions/9662/check-constraint-does-not-work

The answer to this is to type 1990/1/1 within single quotes. 答案是在单引号中键入1990/1/1。

ALTER TABLE EMP 修改表
ADD CONSTRAINT HIRE_DATE_CK 添加CONSTRAINT HIRE_DATE_CK
CHECK (HIREDATE >='1990/01/01') 检查(雇用> ='1990/01/01')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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