CREATE TABLE student_detailS01
(USN VARCHAR(20) NOT NULL,
STUDENT_NAME VARCHAR2(20) NOT NULL,
BRANCH VARCHAR2(20) NOT NULL,
CONTACT_NO NUMBER(10) NOT NULL,
FATHERS_NAME VARCHAR2(20) NOT NULL,
HOME_ADDRESS VARCHAR(50) NOT NULL,
DOB DATE NOT NULL,
LOCAL_ADDRESS VARCHAR2(50),
EMAIL_ID VARCHAR2(20),
DOJ DATE,
HID NUMBER NOT NULL,
PRIMARY KEY (USN,HID)
);
CREATE TABLE MESS(
S_NO NUMBER NOT NULL,
HID NUMBER REFERENCES STUDENT_DETAILS01(HID),
NO_OF_BREAKFAST INT,
NO_OF_MEALS INT,
AMT_OF_BREAKFAST INT,
AMT_OF_MEALS INT,
TOTAL INT NOT NULL,
PRIMARY KEY(S_NO)
);
student_details01
表已执行,但是mess table出现以下错误:
此列列表没有匹配的唯一键或主键。
答案 0 :(得分:0)
ORA-2270 : no matching unique or primary key for this column-list
错误非常简单:当我们在外键中引用的列与父表上的主键或唯一约束不匹配时,会发生此错误。常见的原因是
要解决您的问题,请尝试以下操作:
CREATE TABLE MESS
(
S_NO NUMBER,
S_HID NUMBER,
S_UNO VARCHAR (20), --Added Column
NO_OF_BREAKFAST INT,
NO_OF_MEALS INT,
AMT_OF_BREAKFAST INT,
AMT_OF_MEALS INT,
TOTAL INT NOT NULL,
CONSTRAINT MESS_pk PRIMARY KEY (S_NO),
CONSTRAINT fk_id_dtls FOREIGN KEY
(S_HID, S_UNO)
REFERENCES student_detailS01 (HID, USN)
);