SQL創(chuàng)建表外鍵語句 sql創(chuàng)建外鍵語句?
sql創(chuàng)建外鍵語句?1. Create test main table(class table) class)、Create table test class(classid number,class
sql創(chuàng)建外鍵語句?
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)創(chuàng)建外鍵,
alter table test student
add constraint fk class id外鍵(class id)
references test class(class id)]~]--表tb user
創(chuàng)建表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
創(chuàng)建table tb_2;course(
ID int not null primary key,
name varchar(20)not null
]--table tb_2;mark
創(chuàng)建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)