CREATE TABLE passager
(
codePassager NUMBER(38,0) CONSTRAINT passager_code_pk PRIMARY KEY,
nom VARCHAR2(15) CONSTRAINT passager_nom_nn NOT NULL,
prenom VARCHAR2(15) CONSTRAINT passager_prenom_nn NOT NULL,
adresse VARCHAR2(50) CONSTRAINT passager_adresse NOT NULL,
telephone VARCHAR2(10) CONSTRAINT passager_tel NOT NULL,
ville VARCHAR2(20) CONSTRAINT passager_ville NOT NULL,
pays VARCHAR2(20) CONSTRAINT passager_pays NOT NULL,
status VARCHAR2(1) CONSTRAINT passager_status NOT NULL
);
CREATE TABLE reservation
(
codePassager NUMBER(38,0) CONSTRAINT passager_reservation_codePsg REFERENCES passager(codePassager),
codeReservation NUMBER(38,0) CONSTRAINT reservation_pk PRIMARY KEY (codePassager, codeReservation),
statusReservation VARCHAR2(1) CONSTRAINT reservation_status NOT NULL,
dateReservation VARCHAR2(8) CONSTRAINT reservation_date NOT NULL
);
Oracle告诉我发生错误:
ORA-00907在线“codeReservation NUMBER(38,0)CONSTRAINT reservation_pk PRIMARY KEY(codePassager,codeReservation),“
我花了2个小时寻找答案,但仍然不明白是什么问题。有谁可以帮助我吗?
答案 0 :(得分:1)
由于主键约束不在单个列上,因此需要单独创建,而不是作为列定义的一部分。
CREATE TABLE reservation
(
codePassager NUMBER(38,0) CONSTRAINT passager_reservation_codePsg REFERENCES passager(codePassager),
codeReservation NUMBER(38,0) ,
statusReservation VARCHAR2(1) CONSTRAINT reservation_status NOT NULL,
dateReservation VARCHAR2(8) CONSTRAINT reservation_date NOT NULL,
CONSTRAINT reservation_pk PRIMARY KEY (codePassager, codeReservation)
);