山东大学数据库系统实验一答案

2020-06-19 09:35

实验一 熟悉环境、建立/删除表、插入数据(2学时)

一、 实验内容

利用oracle管理平台登入本人主用户userID,例如user201000300001,在主用户下,创建如下5个表,合理确定每一个表的主键并建立主键,准确输入表格中的3行数据。表名、列名采用英文,oracle不区分大小写,有not null的列代表不允许为空。

1. 教师信息(教师编号、姓名、性别、年龄、院系名称)

test1_teacher:tid char 6 not null、name varchar 10 not null、sex char 2、age int、dname varchar 10。 根据教师名称建立一个索引。 教师编号 100101 100102 100103 教师姓名 张老师 李老师 马老师 性别 男 女 男 年龄 44 45 46 院系名称 计算机学院 软件学院 计算机学院

2. 学生信息(学生编号、姓名、性别、年龄、出生日期、院系名称、班级)

test1_student:sid char 12 not null、name varchar 10 not null、sex char 2、age int、birthday date(oracle的date类型是包含时间信息的,时间信息全部为零)、dname varchar 10、class varchar(10)。 根据姓名建立一个索引。 学号 200800020101 200800020102 200800020103

3. 课程信息(课程编号、课程名称、先行课编号、学分)

test1_course:cid char 6 not null、name varchar 10 not null、fcid char 6、 credit numeric 2,1(其中2代表总长度,1代表小数点后面长度)。 根据课程名建立一个索引。

姓名 王欣 李华 赵岩 性别 女 女 男 年龄 19 20 18 出生日期 院系名称 班级 2010 2009 2009 1994-2-2 计算机学院 1995-3-3 1996-4-4 软件学院 软件学院 课程号 300001 300002 300003 课程名 数据结构 数据库 操作系统 先行课程号 300001 300001 学分 2 2.5 4

4. 学生选课信息(学号、课程号、成绩、教师编号)

test1_student_course:sid char 12 not null、cid char 6 not null、 score numeric 5,1(其中5代表总长度,1代表小数点后面长度)、tid char 6。 学号 200800020101 200800020101 200800020101 课程号 300001 300002 300003 成绩 91.5 92.6 93.7 教师编号 100101 100102 100103

5. 教师授课信息(教师编号、课程编号)

test1_teacher_course:tid char 6 not null,cid char 6 not null。 教师编号 100101 100102 100103 课程号 300001 300002 300003

答案:一、创建表

1、create table test1_teacher(

tid char(6) primary key, name varchar(10) not null, sex char(2), age int,

dname varchar(10) )

2、create table test1_student(

sid char(12) primary key, name varchar(10) not null, sex char(2), age int,

birthday date,

dname varchar(10), class varchar(10) )

3、create table test1_course(

cid char(6) primary key,

name varchar(10) not null, fcid char(6),

credit numeric(2,1) )

4、 create table test1_student_course( sid char(12) , cid char(6) ,

score numeric(5,1), tid char(6),

primary key(sid,cid),

FOREIGN KEY (sid) REFERENCES test1_student(sid), FOREIGN KEY (cid) REFERENCES test1_course(cid), FOREIGN KEY (tid) REFERENCES test1_teacher(tid) )

5、create table test1_teacher_course( tid char(6) , cid char(6) ,

primary key(tid,cid),

FOREIGN KEY (tid) REFERENCES test1_teacher(tid), FOREIGN KEY (cid) REFERENCES test1_course(cid) )

二、创建索引

1、create index index_table1 on test1_teacher(name); 2、create index index_table2 on test1_student(name); 3、create index index_table3 on test1_course(name);

三、插入数据 1、

insert into test1_teacher values('100101','张老师','男',44,'计算机学院'); insert into test1_teacher values('100102','李老师','女',45,'软件学院'); insert into test1_teacher values('100103','马老师','男',46,'计算机学院'); 2、

insert into test1_student values('200800020101','王欣','女',19,to_date('19940202','yyyymmdd'),'计算机学院','2010');

insert into test1_student values('200800020102','李华','女',20,to_date('19950303','yyyymmdd'),'软件学院','2009');

insert into test1_student values('200800020103','赵岩','男',18,to_date('19960404','yyyymmdd'),'软件学院','2009'); 3、

insert into test1_course values('300001','数据结构','',2);

insert into test1_course values('300002','数据库','300001',2.5); insert into test1_course values('300003','操作系统','300001',4); 4、

insert into test1_student_course values('200800020101','300001',91.5,'100101'); insert into test1_student_course values('200800020101','300002',92.6,'100102'); insert into test1_student_course values('200800020101','300003',93.7,'100103'); 5、

insert into test1_teacher_course values ('100101','300001');

insert into test1_teacher_course values ('100102','300002');

insert into test1_teacher_course values ('100103','300003');


山东大学数据库系统实验一答案.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:家委会成员发言稿

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: