重庆交通大学
学生实验报告
实验课程名称 数据库原理
开课实验室 数学实验室
学院 理学院年级 20## 专业班 信息与计算科学2班
学生姓名西西里孩子学 号 68431685
开课时间 2014 至 20## 学年第 1 学期
实验一概念模型的建立
一、实验目的
1、根据给定的题目,把现实世界中的具体事物抽象为某一概念级的模型,即建立整个问题的概念模型,建立起数据库设计人员与用户之间的交流,为数据模型的建立奠定基础。
2、学会认识和分析现实世界,根据对用户需求,描述用户的数据要求:
(1)练习如何从中抽取实体;
(2)练习如何建立各实体之间的联系;
(3)从各实体和实体间的联系,抽取出数据处理的过程。
二、实验内容及要求
(一)实验内容:
通过运用一些软件如power designer、编辑工具如WPS等,对多个实体建立概念模型,通过该方法可以建立直观的概念模型,再通过该模型来建立逻辑模型和物理模型。
(二)实验要求:
1、问题描述
某大学需要使用计算机管理学生信息、成绩信息等,要求如下:
(1)学生信息管理,包含学生的基本信息,如学号、姓名、性别、出生日期等;还要包含学生的简历、社会关系等;
(2)课程管理,包含整个学校开设的所有课程;
(3)教学计划管理,包含设定各系各专业在哪学期开设什么样的课程,学分是多少;
(4)学生选课管理,包含学生在某学期选择什么样的课程;
(5)学生成绩管理,包含学生各课程的成绩、是否补考、补考成绩;
(6)学生奖惩管理,管理学生在校期间所获得的奖励和惩罚记录。
2、根据以上要求,为该大学的计算机管理系统建立数据库的概念模型。
三、实验设备及软件
1、设备:个人电脑
2、软件:PowerDesigner 15、Microsoft SQL Server 20##、WPS Office
四、设计方案
(一)题目:概念模型的建立
(二)设计的主要思路
1、根据前面所要求的应该做的内容及其客观要求,按照步骤进行;
2、进入power designer环境中,如下图:
3、通过点击相应的图标,建立相应的对象。如实体的建立、联系的建立等。如下图:
上图共建立了3个实体:学生、课程和学生选课,在该模型中,也表明了各实体之间的联系,如学生和课程之间有一对多的联系,课程和学生选课之间也具有一对多的联系。
3、实体属性的建立
双击实体对象,弹出实体描述对话框;如下图:
要求输入输入实体的名称(name)、实体代码(code)、实体标签(label)。点击attributes(属性)按钮,进入实体的属性输入框,如下图:
在弹出框中输入多个属性,包含属性的名称(name)、代码(code)、数据类型(data type),对于数据类型可以选择,如下图:
在输入属性时注意属性的特性:
I:为主码(在PowerDesigner 15里P为主码);如果是主码,则表明该属性唯一标识一个实体。
M:为是否允许为空;如果选中,则表示该属性不允许为空。
(三)主要功能
1、通过整体把握,能够对学生的基本信息(如学号、姓名、性别出生日期、社会关系、学生简历)进行统一的、有效地管理;
2、能清晰的描绘出关于学生实体以及有和学生有关系的实体情况,可以对学校开设的课程进行管理;
3、能对教学计划、学生选课、学生成绩、学生奖惩进行管理;
五、主要代码
/*==============================================================*/
/* DBMS name: Microsoft SQL Server 2005 */
/* Created on: 2014/12/23 19:01:33 */
/*==============================================================*/
if exists (select 1
from sysobjects
where id = object_id('cla')
and type = 'U')
drop table cla
go
if exists (select 1
from sysobjects
where id = object_id('col')
and type = 'U')
drop table col
go
if exists (select 1
from sysobjects
where id = object_id('jcxm')
and type = 'U')
drop table jcxm
go
if exists (select 1
from sysobjects
where id = object_id('ltest')
and type = 'U')
drop table ltest
go
if exists (select 1
from sysobjects
where id = object_id('maj')
and type = 'U')
drop table maj
go
if exists (select 1
from sysobjects
where id = object_id('nat')
and type = 'U')
drop table nat
go
if exists (select 1
from sysobjects
where id = object_id('"plan"')
and type = 'U')
drop table "plan"
go
if exists (select 1
from sysobjects
where id = object_id('pol')
and type = 'U')
drop table pol
go
if exists (select 1
from sysobjects
where id = object_id('selcla')
and type = 'U')
drop table selcla
go
if exists (select 1
from sysobjects
where id = object_id('shehuiguanxi')
and type = 'U')
drop table shehuiguanxi
go
if exists (select 1
from sysobjects
where id = object_id('stu')
and type = 'U')
drop table stu
go
if exists (select 1
from sysobjects
where id = object_id('stufencon')
and type = 'U')
drop table stufencon
go
if exists (select 1
from sysobjects
where id = object_id('stuhj')
and type = 'U')
drop table stuhj
go
if exists (select 1
from sysobjects
where id = object_id('stutext')
and type = 'U')
drop table stutext
go
if exists (select 1
from sysobjects
where id = object_id('term')
and type = 'U')
drop table term
go
if exists (select 1
from sysobjects
where id = object_id('xueyear')
and type = 'U')
drop table xueyear
go
if exists (select 1
from sysobjects
where id = object_id('xykcgl')
and type = 'U')
drop table xykcgl
go
/*==============================================================*/
/* Table: cla */
/*==============================================================*/
create table cla (
clano varchar(10) not null,
clana varchar(40) not null,
constraint PK_CLA primary key nonclustered (clano)
)
go
/*==============================================================*/
/* Table: col */
/*==============================================================*/
create table col (
colno varchar(10) not null,
colna varchar(40) not null,
constraint PK_COL primary key nonclustered (colno)
)
go
/*==============================================================*/
/* Table: jcxm */
/*==============================================================*/
create table jcxm (
jxno varchar(10) not null,
jxna varchar(60) not null,
constraint PK_JCXM primary key nonclustered (jxno)
)
go
/*==============================================================*/
/* Table: ltest */
/*==============================================================*/
create table ltest (
ltestno varchar(10) not null,
ltestna varchar(20) not null,
testtime float not null,
constraint PK_LTEST primary key nonclustered (ltestno)
)
go
/*==============================================================*/
/* Table: maj */
/*==============================================================*/
create table maj (
majno varchar(10) not null,
colno varchar(10) not null,
majna varchar(40) not null,
constraint PK_MAJ primary key nonclustered (majno)
)
go
/*==============================================================*/
/* Table: nat */
/*==============================================================*/
create table nat (
natno varchar(6) not null,
natna varchar(30) not null,
constraint PK_NAT primary key nonclustered (natno)
)
go
/*==============================================================*/
/* Table: "plan" */
/*==============================================================*/
create table "plan" (
majno varchar(10) not null,
clano varchar(10) not null,
xyeno varchar(6) not null,
termno int not null
constraint CKC_TERMNO_PLAN check (termno in (1,2)),
xuefen float not null,
constraint PK_PLAN primary key nonclustered (majno, clano)
)
go
/*==============================================================*/
/* Table: pol */
/*==============================================================*/
create table pol (
polno varchar(10) not null,
polna varchar(40) not null,
constraint PK_POL primary key nonclustered (polno)
)
go
/*==============================================================*/
/* Table: selcla */
/*==============================================================*/
create table selcla (
majno varchar(10) not null,
clano varchar(10) not null,
stuno varchar(15) not null,
ltestno varchar(10) not null,
constraint PK_SELCLA primary key nonclustered (majno, clano, stuno)
)
go
/*==============================================================*/
/* Table: shehuiguanxi */
/*==============================================================*/
create table shehuiguanxi (
stuno varchar(15) not null,
gxno varchar(6) not null,
gxna varchar(40) not null,
constraint PK_SHEHUIGUANXI primary key nonclustered (stuno, gxno)
)
go
/*==============================================================*/
/* Table: stu */
/*==============================================================*/
create table stu (
stuno varchar(15) not null,
stuna varchar(40) not null,
majno varchar(10) not null,
nianji int not null,
sex char(2) not null default '1'
constraint CKC_SEX_STU check (sex in ('1','2')),
natno varchar(6) not null,
polno varchar(10) null,
birt datetime null,
constraint PK_STU primary key nonclustered (stuno)
)
go
/*==============================================================*/
/* Table: stufencon */
/*==============================================================*/
create table stufencon (
stextci int not null,
majno varchar(10) not null,
clano varchar(10) not null,
stuno varchar(15) not null,
gfen float not null,
constraint PK_STUFENCON primary key nonclustered (stextci, majno, clano, stuno)
)
go
/*==============================================================*/
/* Table: stuhj */
/*==============================================================*/
create table stuhj (
stuno varchar(15) not null,
jxno varchar(10) null,
constraint PK_STUHJ primary key nonclustered (stuno)
)
go
/*==============================================================*/
/* Table: stutext */
/*==============================================================*/
create table stutext (
stuno varchar(15) not null,
jlthing text not null,
constraint PK_STUTEXT primary key nonclustered (stuno)
)
go
/*==============================================================*/
/* Table: term */
/*==============================================================*/
create table term (
termno int not null
constraint CKC_TERMNO_TERM check (termno in (1,2)),
xyeno varchar(6) not null,
constraint PK_TERM primary key nonclustered (termno, xyeno)
)
go
/*==============================================================*/
/* Table: xueyear */
/*==============================================================*/
create table xueyear (
xyeno varchar(6) not null,
constraint PK_XUEYEAR primary key nonclustered (xyeno)
)
go
/*==============================================================*/
/* Table: xykcgl */
/*==============================================================*/
create table xykcgl (
clano varchar(10) not null,
colno varchar(10) not null,
constraint PK_XYKCGL primary key nonclustered (clano)
)
go
六、测试结果及说明
(一)模型图
(二)表格清单
七、实验体会
转眼间,数据库的学习已结束,经过一个学期的数据库课程的学习,使得我对数据库的一些基本知识有了比较完整的理解,同时,也使得我掌握了有关创建数据库以及对数据库的操作的一些基础知识。
这门课是一门从头学起的课程,在学习的过程中有一些难度,经过长时间的不断努力,虽然基础不是很好,但仍能跟上老师的脚步,不断获得一些有关数据库的知识。要如何运用这些知识,上机实验是必不可少的。我们专业实验时间较少,这些时间自是非常珍贵,但每次上机实验的内容都能够让我们了解到如何将学到的知识转化为实际的应用,使得学到的知识更加具有实际现实意义。只有在实践中才能找到知识漏洞,从而才能不断改进,不断进步,使得数据库知识灵活运用于实际,更好地用来解决实际问题。通过上机实践使我更加深刻的理解了所学知识,学到了更多的关于实际操作的知识和技巧,培养了自主学习的能力。
在实验的过程中,让我明白了,很多事情不是想象中的那么简单。只有通过实验,在实践中发现并改正问题,才能不断提升自己的能力,增强自己解决问题的能力,培养自信。只有不断努力、不断尝试,才有可能成功。