/*==============================================================*/
/* DBMS name: ORACLE Version 9i */
/* Created on: 2007-11-7 15:18:34 */
/*==============================================================*/
/*==============================================================*/
/* Table: "class" */
/*==============================================================*/
create table "class" (
"cid" INTEGER not null,
"cname" VARCHAR2(20) not null
);/*==============================================================*/
/* Index: "class_PK" */
/*==============================================================*/
create unique index "class_PK" on "class" (
"cid" ASC
);/*==============================================================*/
/* Table: "student" */
/*==============================================================*/
create table "student" (
"sid" INTEGER not null,
"cid" INTEGER not null,
"sname" VARCHAR2(10) not null,
"birth" DATE not null,
"age" NUMBER(3) not null
);/*==============================================================*/
/* Index: "student_PK" */
/*==============================================================*/
create unique index "student_PK" on "student" (
"sid" ASC
);/*==============================================================*/
/* Index: "Relationship_1_FK" */
/*==============================================================*/alter table "student"
add constraint FK_Relationship11 foreign key ("cid")
references "class" ("cid");报错:
alter table "student"
add constraint FK_Relationship11 foreign key ("cid")
references "class" ("cid")
ORA-02270: no matching unique or primary key for this column-list
create table "student " (
"sid " INTEGER not null,
"cid " INTEGER not null,
"sname " VARCHAR2(10) not null,
"birth " DATE not null,
"age " NUMBER(3) not null
)
constraint "student_PK " primary key(
"sid " ASC
);
drop index CLASS_PK
然后
alter table "class" add constraint CLASS_PK primary key( "sid" ASC )
再
alter table "student "
add constraint FK_Relationship11 foreign key ( "cid ")
references "class " ( "cid ");