SQL脚本:

 --建表
--student表+注释
create table student(
sno varchar2(3) not null,
sname varchar2(9) not null,
ssex varchar2(3) not null,
sbirthday date,
sclass varchar2(5),
constraint pk_student primary key(sno)
);
comment on column student.sno is '学号(主键)';
comment on column student.sname is '学生姓名';
comment on column student.ssex is '学生性别';
comment on column student.sbirthday is '学生出生年月日';
comment on column student.sclass is '学生所在班级';
--course表+注释
create table course(
cno varchar2(5) not null,
cname varchar2(15) not null,
tno varchar2(3) not null,
constraint pk_course primary key(cno)
);
comment on column course.cno is '课程编号(主键)';
comment on column course.cname is '课程名称';
comment on column course.tno is '教工编号(外键)';
--score表+注释
create table score(
sno varchar2(3) not null,
cno varchar2(5) not null,
degree number(4,1),
constraint pk_score primary key(sno,cno)
);
comment on column score.sno is '学号(主键)';
comment on column score.cno is '课程编号(主键)';
comment on column score.degree is '成绩';
--teacher表+注释
create table teacher(
tno varchar2(3) not null,
tname varchar2(9) not null,
tsex varchar2(3) not null,
tbirthday date,
prof varchar2(9),
depart varchar2(15) not null,
constraint pk_teacher primary key(tno)
);
comment on column teacher.tno is '教工编号(主键)';
comment on column teacher.tname is '教工姓名';
comment on column teacher.tsex is '教工性别';
comment on column teacher.tbirthday is '教工出生年月';
comment on column teacher.prof is '职称';
comment on column teacher.depart is '教工所在单位';
--添加外键
alter table course add constraint fk_tno foreign key(tno) references teacher(tno);
alter table score add constraint fk_sno foreign key(sno) references student(sno);
alter table score add constraint fk_cno foreign key(cno) references course(cno);
--添加数据
--Student表
insert into student(sno,sname,ssex,sbirthday,sclass) values(108,'曾华','男',to_date('1977-09-01','yyyy-mm-dd'),95033);
insert into student(sno,sname,ssex,sbirthday,sclass) values(105,'匡明','男',to_date('1975-10-02','yyyy-mm-dd'),95031);
insert into student(sno,sname,ssex,sbirthday,sclass) values(107,'王丽','女',to_date('1976-01-23','yyyy-mm-dd'),95033);
insert into student(sno,sname,ssex,sbirthday,sclass) values(101,'李军','男',to_date('1976-02-20','yyyy-mm-dd'),95033);
insert into student(sno,sname,ssex,sbirthday,sclass) values(109,'王芳','女',to_date('1975-02-10','yyyy-mm-dd'),95031);
insert into student(sno,sname,ssex,sbirthday,sclass) values(103,'陆君','男',to_date('1974-06-03','yyyy-mm-dd'),95031);
--teacher表
insert into teacher(tno,tname,tsex,tbirthday,prof,depart) values(804,'李诚','男',to_date('1958/12/02','yyyy-mm-dd'),'副教授','计算机系');
insert into teacher(tno,tname,tsex,tbirthday,prof,depart) values(856,'张旭','男',to_date('1969/03/12','yyyy-mm-dd'),'讲师','电子工程系');
insert into teacher(tno,tname,tsex,tbirthday,prof,depart) values(825,'王萍','女',to_date('1972/05/05','yyyy-mm-dd'),'助教','计算机系');
insert into teacher(tno,tname,tsex,tbirthday,prof,depart) values(831,'刘冰','女',to_date('1977/08/14','yyyy-mm-dd'),'助教','电子工程系');
--course表(添加外键后要先填teacher表中数据去满足外键约束)
insert into course(cno,cname,tno) values('3-105','计算机导论',825);
insert into course(cno,cname,tno) values('3-245','操作系统',804);
insert into course(cno,cname,tno) values('6-166','数字电路',856);
insert into course(cno,cname,tno) values('9-888','高等数学',831);
--score表(添加外键后要先填Student,course表中数据去满足外键约束)
insert into score(sno,cno,degree) values(103,'3-245',86);
insert into score(sno,cno,degree) values(105,'3-245',75);
insert into score(sno,cno,degree) values(109,'3-245',68);
insert into score(sno,cno,degree) values(103,'3-105',92);
insert into score(sno,cno,degree) values(105,'3-105',88);
insert into score(sno,cno,degree) values(109,'3-105',76);
insert into score(sno,cno,degree) values(101,'3-105',64);
insert into score(sno,cno,degree) values(107,'3-105',91);
insert into score(sno,cno,degree) values(108,'3-105',78);
insert into score(sno,cno,degree) values(101,'6-166',85);
insert into score(sno,cno,degree) values(107,'6-166',79);
insert into score(sno,cno,degree) values(108,'6-166',81);

Student表                                                                                             Course表

                                        

Score表

Teacher表

Oracle数据库建表+添加数据练习的更多相关文章

  1. PowerDesigner连接Oracle数据库建表序列号实现自动增长

    原文:PowerDesigner连接Oracle数据库建表序列号实现自动增长 创建表就不说了.下面开始介绍设置自动增长列. 1 在表视图的列上创建.双击表视图,打开table properties — ...

  2. T-SQL - query01_创建数据库|创建表|添加数据|简单查询

    时间:2017-09-29  整理:byzqy 本篇以"梁山好汉花名册"为例,记录MS SQLServer T-SQL语句的使用,包含命令: 创建数据库 | 删除数据库 创建表 | ...

  3. Oracle数据库在给表添加字段的sql中用comment报错

    原因:不同于mysql,Oracle数据库在添加表字段时不能直接用comment,而是单独写一个sql语句,如下: alter table SYS_USER add SENDMSG_LASTTIME ...

  4. Oracle建表添加数据

  5. Oracle数据库建表并用SQL编程分等级

    --创建学生表create table XS_543 ( XH char(6) not null , XM varchar2(20) not null, ZYM varchar2(10), XB ch ...

  6. oracle数据库建表

    create or replace directory dumpdir as 'E:\oracle\dumpdir';create temporary tablespace ydxt_temp tem ...

  7. OREACLE 数据库建表 添加判断表是否存在 不存在则新建

    declare  cnt number; begin   ---查询要创建的表是否存在   select count(*)into cnt from user_tables where table_n ...

  8. oracle数据库建表设置自增主键

    create sequence userlogin_ID increment by 1 start with 1 minvalue 1 maxvalue 9999999999999999 nocach ...

  9. 定时从远程的数据库中取数据,然后把取出来的数据插入或更新本地的oracle数据库的表

    最近项目中有一种需求: 大致需求是这样的 通过给定的 用户名和密码 要定时从远程的数据库中取数据,然后把取出来的数据插入或更新本地的oracle数据库的表 项目的结构式struts1 hibernat ...

随机推荐

  1. 【微博SDK调用逻辑】微博SDK的调用逻辑,最好自己还是写一个例子,试一下!!!

    逻辑是这样的,谢谢给我讲东西的开发哥哥,嘻嘻~~~  1.点击微博登录,SDK会打开微博客户端,然后点击登陆(如果已经登录了会出现一个当前app跟微博交互的图片界面,然后提示“正在获取授权信息”,如果 ...

  2. Bridge(桥接)-对象结构型模式

    1.意图 将抽象部分与它的实现部分分离,使它们都可以独立地变化. 2.动机 在抽象类与它的实现之间起到桥梁作用,使它们可以独立地变化. 3.适用性 不希望在抽象和它的实现部分之间有一个固定的绑定关系. ...

  3. AngularJS学习--- 事件处理(Event Handlers) ng-click操作 step 10

    本文主要通过介绍ng-click方法来对angularjs中的事件处理方法做个了解. 1.切换目录 git checkout step- npm start 2.效果 点击右边的小图片,那么左边框中将 ...

  4. protoc-gen-php --php_out: protoc-gen-php: Plugin output is unparseable.

    背景 业务需要用protobuffer 进行通讯. client: php server: c++ 在github 上找到 Protobuf-PHP (https://github.com/drslu ...

  5. Daily Scrum 12.11

    今日完成任务: 解决了类型同时存在于两个自动生成的DLL中导致编译不通过的问题:修复了主页标签显示的BUG:修复异常,网站可以在服务器端正常运行. 明日任务: 黎柱金 解决上传文档时建立文档和标签联系 ...

  6. [转]理解dropout

    理解dropout 原文地址:http://blog.csdn.net/stdcoutzyx/article/details/49022443     理解dropout 注意:图片都在github上 ...

  7. linux下挂载新硬盘

    挂载好新硬盘后输入fdisk -l命令看当前磁盘信息 1.创建新硬盘分区 用fdisk  + 路径 进行分区 进入磁盘,对磁盘进行分区 #fdisk /dev/sdb Command (m for h ...

  8. PostScript的简单例子-用粗线画一个圆

    一 近期需要用到PostScript,查询资料学习PS的语法 简单的画一个圆的例子 %!PS-Adobe-3.0 /inch{72 mul} def 4.25 inch 5.5 inch 1.5 in ...

  9. ARM Linux 3.x的设备树(Device Tree)

    http://blog.csdn.net/21cnbao/article/details/8457546 宋宝华 Barry Song <21cnbao@gmail.com> 1.     ...

  10. img图片放大控件 lightbox.js

    1.引入相关js,css jquery-1.7.2.min.js,lightbox.css,lightbox.js   2 图片增加<a href="大图片地址" rel=& ...