首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

oracle下令建立主键外键

2012-09-08 
oracle命令建立主键外键1、创建一张学生表SQL create table t_stu(2stuid number(10) primary key,3stunam

oracle命令建立主键外键

1、创建一张学生表

SQL> create table t_stu(  2  stuid number(10) primary key,  3  stuname varchar2(20) not null,  4  stusex varchar2(2) default '男' check(stusex in('男','女'))); Table created Executed in 0.547 seconds


2、创建一张课程表

SQL> create table t_couse(  2  couseid number(10) primary key,  3  cousename varchar2(20) not null,  4  cousetype varchar2(4)); Table created Executed in 0.062 seconds


3、创建一张学生课程成绩表(包括主外键)

SQL> create table t_score(  2  scoreid number(10) primary key,  3  stuid number(10) references t_stu(stuid),  4  couseid number(10),  5  constraint fk_couseid foreign key(couseid)  6  references t_couse(couseid)  7  on delete cascade); Table created


 

热点排行