create table stu01(
sid varchar(100),
sname varchar2(100)
--constraint PK_stu01_sid primary key (sid)
)
--添加約束(主鍵)
alter table stu01 add constraint PK_stu01_sid primary key(sid) ---添加主鍵約束
alter table stu01 drop constraint PK_stu01_sid ---刪除主鍵約束
create table stu02(
sid varchar2(100),
sname varchar2(100),
constraint PK_stu02_sid primary key(sid),
constraint UK_stu02_sname unique(sname)
)
create table stu03(
sid varchar2(100),
sname varchar2(100) not null,
constraint PK_stu03_sid primary key(sid),
constraint UK_stu03_sname unique(sname)
)
create table stu04(
sid varchar2(100),
sname varchar2(100) not null,
constraint PK_stu04_sid primary key(sid),
constraint UK_stu04_sname unique(sname)
)
--創(chuàng)建課程表
create table course01(
cid varchar2(100),
cname varchar2(100) not null,
constraint PK_course01_cid primary key(cid),
constraint UK_course01_cname unique(cname)
)
--最后添加成績(jī)表,外鍵約束課程表和學(xué)生表
create table mark02(
sid varchar2(100),
cid varchar2(100),
mark number,
constraint PK_mark02_sidAndcid primary key(sid,cid),
constraint FK_mark02_sid foreign key(sid) references stu04(sid),
constraint FK_mark02_cid foreign key(cid) references course01(cid),
constraint UK_mark02_mark unique(mark)
)
--刪除外鍵約束
alter table mark01 drop constraint FK_mark02_sid
alter table mark01 drop constraint FK_mark02_cid