ORACLE 如何建立表外键
例: 学生表student (id, name , sex )
成绩表score (id ,math )
如何创建表,要求 有主键,有约束
解: create table student(id char(10),name varchar(8),sex char(1));
alter table student add constraint pk_student primary key(id);
create table score( id char(10),math number(5,2));
alter table score add constraint fk_scroe foreign key(id) references student;
* 主键与外键:
键是表中的列(可以是一列,也可以是几列),主键用于唯一的标识表中的数据项;外键用于连接父表和子表。而所谓的父表和子表是根据3NF
范式的要求,为了消除传递依赖,将原表拆成2个相互关联的表,而这个关联就是外键。