/* DROP TABLE STATEMENTS*/
DROP TABLE BUILDING CASCADE CONSTRAINTS PURGE;
DROP TABLE ROOM CASCADE CONSTRAINTS PURGE;
DROP TABLE CONFERENCESESSION CASCADE CONSTRAINTS PURGE;
DROP TABLE SPEAKER CASCADE CONSTRAINTS PURGE;
/* CREATE TABLE STATEMENTS*/
CREATE TABLE BUILDING(
BUILDINGNO CHAR(2),
BUILDINGWING VARCHAR2(15),
BUILDINGLANE VARCHAR2(15),
CONSTRAINT BUILDING_PK PRIMARY KEY(BUILDINGNO));
CREATE TABLE ROOM(
BUILDINGNO CHAR(2),
ROOMNO CHAR(2),
ROOMCAPACITY NUMBER(3),
CONSTRAINT ROOM_PK PRIMARY KEY(BUILDINGNO, ROOMNO),
CONSTRAINT ROOM_FK FOREIGN KEY(BUILDINGNO) REFERENCES BUILDING(BUILDINGNO));
CREATE TABLE SPEAKER(
SPEAKERID CHAR(2),
SPEAKERNAME VARCHAR2(20),
SPEAKERADDRESS VARCHAR2(50),
SPEAKERPHONE CHAR(12),
CONSTRAINT SPEAKER_PK PRIMARY KEY(SPEAKERID));
CREATE TABLE CONFERENCESESSION(
SESSIONID CHAR(4),
BUILDINGNO CHAR(2),
ROOMNO CHAR(2),
SPEAKERID CHAR(2),
SESSIONDATE DATE,
SESSIONPRICE NUMBER(4, 2),
CONSTRAINT CONFERENCE_PK PRIMARY KEY(SESSIONID),
CONSTRAINT CONFERENCE_FK1 FOREIGN KEY(BUILDINGNO)REFERENCES BUILDING(BUILDINGNO),
CONSTRAINT CONFERENCE_FK2 FOREIGN KEY(ROOMNO) REFERENCES ROOM(ROOMNO),
CONSTRAINT CONFERENCE_FK3 FOREIGN KEY(SPEAKERID) REFERENCES SPEAKER(SPEAKERID));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
运行上面的代码时出现此错误:
Table BUILDING掉线了。
表格ROOM下降。
从命令行中的第4行开始出错 -
DROP TABLE CONFERENCESION CASCADE CONSTRAINTS PURGE
错误报告 -
ORA-00942:表或视图不存在
00942. 00000 - “表或视图不存在”
*原因:
*行动:表扬声器掉线了。
表格构建已创建。
表格ROOM已创建。
表扬声器已创建。
从命令行中的第28行开始出错 -
创建表会议(
SESSIONID CHAR(4),
BUILDINGNO CHAR(2),
ROOMNO CHAR(2),
SPEAKERID CHAR(2),
会期日期,
SESSIONPRICE NUMBER(4,2),
CONSTRAINT CONFERENCE_PK PRIMARY KEY(SESSIONID),
约束会议_FK1外键(BUILDINGNO)参考建筑物(BUILDINGNO),
CONSTRAINT CONFERENCE_FK2 FOREIGN KEY(ROOMNO)REFERENCES ROOM(ROOMNO),
约束会议_FK3 FOREIGN KEY(SPEAKERID)参考语音(SPEAKERID))错误报告 -
查找正确的列名称
ORA-02270:此列列表没有匹配的唯一键或主键 02270. 00000 - “此列列表没有匹配的唯一或主键”
*原因:CREATE / ALTER TABLE语句中的REFERENCES子句给出了一个列表,其中引用的表中没有匹配的唯一或主键约束。
*操作:使用ALL_CONS_COLUMNS目录视图
任何帮助?
答案 0 :(得分:5)
CONSTRAINT CONFERENCE_FK2 FOREIGN KEY(ROOMNO) REFERENCES ROOM(ROOMNO)
:外键必须引用另一个表的整个主键(或唯一键)。所以只需添加buildingno:
CONSTRAINT CONFERENCE_FK2 FOREIGN KEY(BUILDINGNO, ROOMNO) REFERENCES ROOM(BUILDINGNO, ROOMNO)