我试图在sql中创建一个表,但是当我从表COURSE
添加外键时,它会给我一个错误。用其他外键吧;任何人都可以告诉我原因。
这是我的查询
CREATE TABLE ENROLL (
Stu_ID NUMBER NOT NULL,
Prog_ID VARCHAR2(20) NOT NULL,
Crs_ID NUMBER NOT NULL,
Crs_Sec_ID VARCHAR2(20) NOT NULL,
Enroll_Outcome CHAR(1) NOT NULL,
PRIMARY KEY(Stu_ID),
FOREIGN KEY(Stu_ID) REFERENCES STUDENT(Stu_ID),
FOREIGN KEY(Prog_ID) REFERENCES PROGRAMS(Prog_ID),
FOREIGN KEY (Crs_Sec_ID) REFERENCES COURSE_SECTION (Crs_Sec_ID),
FOREIGN KEY(Crs_ID) REFERENCES COURSE(Crs_ID));
这是输出
Error starting at line : 126 in command -
CREATE TABLE ENROLL (
Stu_ID NUMBER NOT NULL,
Prog_ID VARCHAR2(20) NOT NULL,
Crs_ID NUMBER NOT NULL,
Crs_Sec_ID VARCHAR2(20) NOT NULL,
Enroll_Outcome CHAR(1) NOT NULL,
PRIMARY KEY(Stu_ID),
FOREIGN KEY(Stu_ID) REFERENCES STUDENT(Stu_ID),
FOREIGN KEY(Prog_ID) REFERENCES PROGRAMS(Prog_ID),
FOREIGN KEY (Crs_Sec_ID) REFERENCES COURSE_SECTION (Crs_Sec_ID),
FOREIGN KEY(Crs_ID) REFERENCES COURSE(Crs_ID))
Error report -
SQL Error: ORA-02267: column type incompatible with referenced column type
02267. 00000 - "column type incompatible with referenced column type"
*Cause: The datatype of the referencing column is incompatible with the
再次,它与所有其他没有Crs_ID的外键一起运行良好。
答案 0 :(得分:0)
基本上说的是Enroll表中的Couse ID和Couse表中的Couse ID是不兼容的。两列都应具有相同的类型和属性(不为null),以便建立外键关系。
要检查的事项: