Oracle中的日期检查约束

时间:2013-11-24 14:18:10

标签: oracle

CREATE TABLE TEMP_STUDENT
(STUDID NUMBER(8,0) NOT NULL PRIMARY KEY,
FIRST_NAME VARCHAR2(25),
LAST_NAME VARCHAR2(25),
ZIP VARCHAR2(5) FOREIGN KEY REFERENCES ZIPCODE(ZIP),
REGISTRATION_DATE DATE NOT NULL CHECK (REGISTRATION_DATE > TO_DATE('1-JAN-2000 00:00:00','DD-MON-YYYY HH24:MI:SS')))

这有什么问题,请帮忙。我收到错误:'错过了正确的家长'

2 个答案:

答案 0 :(得分:1)

问题在于您的FOREIGN KEY REFERENCES检查。

您想要this

  create table zipcode
(
  zip varchar2(5) primary key
);

CREATE TABLE TEMP_STUDENT
(STUDID NUMBER(8,0) NOT NULL PRIMARY KEY,
FIRST_NAME VARCHAR2(25),
LAST_NAME VARCHAR2(25),
ZIP VARCHAR2(5),
 REGISTRATION_DATE DATE NOT NULL CHECK (REGISTRATION_DATE > TO_DATE('1-JAN-2000 00:00:00','DD-MON-YYYY HH24:MI:SS')),
constraint foreign key REFERENCES ZIPCODE(ZIP));

答案 1 :(得分:-1)

alter TEMP_STUDENT add constraint REGISTRATION_DATE_CHK check (REGISTRATION_DATE > TO_DATE('1-JAN-2000 00:00:00','DD-MON-YYYY HH24:MI:SS'))