SQL创建表外键语句 sql创建外键语句?

sql创建外键语句?1. Create test main table(class table) class)、Create table test class(classid number,class

sql创建外键语句?

1. Create test main table(class table) class)、

Create table test class(classid number,classuname VARCHAR2(20))

2ustudent)、

Create table testustudent(stuid number,stuuname VARCHAR2(200),classuid number)

3。主表(class table)uclass)添加唯一主键,

alter table testuclass

添加约束pkuclassuid主键(classuid)

4。子表(student table) student)创建外键,

alter table test student

add constraint fk class id外键(class id)

references test class(class id)]~]--表tb user

创建表tb user(

id int not null,

username varchar(32)not null

]--give tb user添加主键alter table tb_u2;user add constraint pk_2;Users primary key(ID)

--table tb_2;course

创建table tb_2;course(

ID int not null primary key,

name varchar(20)not null

]--table tb_2;mark

创建table tb_2;mark(

uid int not null,

CID int not null,

mark int not null,

主键(uid,CID)

--give TB [mark add foreign key

alter table TB mark add constraint fk uid foreign key(uid)references TB user(id)

alter table TB mark add constraint fk CID foreign key(CID)references TB course(id)