任务5独立实践SQL数据模型分析

为创建“教务管理”数据库,首先要创建数据模型。请完成以下任务。

(1)分析报表和做出必要的调研,创建数据模型。

  1. 列出可能的实体。
    学校、学院、专业、班级、学生、教师、课程。

  2. 列出实体的联系、联系的类型和多重性的值。
    实体的联系
    在这里插入图片描述

联系的类型

一个学校至少有一个学院,一个学院至多被一个学校选择。学校—>学院,1:多
一个院系至少选择一个专业,一个专业至多被一个院系选择。院系—>专业,1:多
一个班级至多选择一个专业,一个专业至少被一个班级选择。班级—>专业,1:多
一个学生至多选择一个班级,一个班级对应多个学生。学生—>班级,1:多
一个专业可以设置多个不相同课程,课程可以被多个不同专业选择。
专业<—>课程,多:多。分析:根据番职校的需求,专业与课程关系是一对多。
一个学生除了修读本专业规定的课程之外,还应该修读其它的(选修)课程,一个学生可以选择多个不相同课程,同一课程可以不选择或选择不同需求的学生。
学生<—>课程,多:多。
一个老师至少任一门课程,一门课程对应多个不同的任课老师。
老师<—>课程,多:多。
提示:在标识实体类之间关系时,另一种方法是在用户的需求说明中找动词或动词短语。

具有多重属性值的字段

课程类型(一体化、纯理论、纯实践)、核心课程(重要True或不重要False)、课程性质(必修课、选修课)、考核方式(考试、考查)、课程归属(基本素质与能力课、职业能力课)

  1. 列出实体的主要属性和属性域,确定每个实体的关键字,其余属性可在后期增加。
Create DataBase 教务管理
go
use 教务管理
go

Create Table 学校
(学校编号 int identity(1,1) constraint column_学校编号_pk Primary key not null,
学校名称 varchar(30) not null,
)

Create Table 学院
(系部编号 int identity(1,1) constraint column_系部编号_pk Primary key not null,
系部名 varchar(20)  not null,
学校编号 int not null)

Create Table 专业
(专业编号 int identity(1,1) constraint column_专业编号_pk Primary key not null,
专业名称 varchar(20) not null,
系部编号 int not null)

Create Table 班级
(班级编号 int identity(1,1) constraint column_班级编号_pk Primary key not null,
班级名称 varchar(20) not null,
专业编号 int not null
)

Create Table 学生
(学号 char(9) constraint column_学号_pk Primary key not null,
姓名 char(8) null,
班级编号 int not null)

Create Table 教师
(教师编号 int identity(1,1) constraint column_教师编号_pk Primary key not null,
姓名 char(8) not null,
手机号码 char(20) null)

Create Table 课程
(课程编号 int identity(1,1) constraint column_课程编号_pk Primary key not null,
课程名称 varchar (20) not null,
学分 tinyint constraint ck_学分 check(学分>0 and 学分<100),
开课学年 datetime null,
开课学期 tinyint constraint ck_开课学期 check(开课学期>0 and 开课学期<100) null,
理论学时 tinyint constraint ck_理论学时 check(理论学时>0 and 理论学时<100) null,
实践学时 tinyint constraint ck_实践学时 check(实践学时>0 and 实践学时<100) null,
备注 nvarchar(Max) null,
课程类型编号 int not null,
核心课程编号 int not null,
课程性质编号 int not null,
考核方式编号 int not null,
课程归属编号 int not null,
开课学院编号 int not null
)

/*中间表*/

Create Table 课程_教师
(教师编号 int not null,
课程编号 int not null,
课程名 varchar (20) 
constraint column_教师编号_课程编号_pk Primary Key(教师编号, 课程编号)
)

Create Table 学生_课程
(学生编号 char(9) not null,
课程编号 int not null,
成绩 tinyint constraint ck_成绩 check(成绩>=0 and 成绩<100) 
constraint DF_学生_课程_成绩 default(0)
Constraint column_学生编号_课程编号_pk Primary Key(学生编号,课程编号)
)

Create Table 专业_课程
(专业编号 int not null,
课程编号 int not null,
Constraint column_专业_课程_pk Primary Key(专业编号,课程编号)
)

/*********************多值属性****************************/
--课程类型={一体化、纯理论、纯实践}
Create Table 课程_课程类型
(课程类别编号 int identity(1,1) constraint column_课程_课程类型_pk Primary key  not null,
课程类型 char(9) not null,
)

--核心课程={重要、不重要}
Create Table 课程_核心课程
(核心课程编号 int identity(1,1) constraint column_课程_核心课程_pk Primary key not null,
核心课程 bit  constraint DF_课程_核心课程  default('0'),
)

--课程性质={必修课、选修课}
Create Table 课程_课程性质
(课程性质编号 int identity(1,1) constraint column_课程_课程性质_pk Primary key not null,
课程性质 char(9) null,
)

--考核方式={考试、考查}
Create Table 课程_考核方式
(考核方式编号 int identity(1,1) constraint column_课程_考核方式_pk Primary key not null,
考核方式 char(9) not null,
)

--课程归属={基本素质与能力课、职业能力课}
Create Table 课程_课程归属
(课程归属编号 int identity(1,1) constraint column_课程_课程归属_pk Primary key  not null,
课程归属 char(20) not null, 
)

--Other SQK practice tests
select [name],[definition],[is_system_named]                             
from [sys].[default_constraints]
select * from sys.key_constraints
select * from sys.foreign_keys
alter table [班级] drop constraint [column_班级(班级编号)_pk]
alter table 班级
alter column 班级编号 identity(1,1) null 
alter table 班级
alter column 班级名称 varchar(21) null 

  1. 绘出E-R图。
    在这里插入图片描述

(2)需要询问教务处以进行核实的部分。

有待探讨的属性有课程归属,需要向教务处咨询需求。
对复合属性的处理:
F(班级编号)= 学生人数,简单属性学生人数依赖于学号和班级编号,通过count函数可以统计出学院、专业和班级的人数;
复合属性总学时=理论+实践;
F(成绩) = 绩点,绩点函数依赖于属于成绩,通过成绩可以知道学生该门课程成绩的绩点;
F(必修学分或选修学分) = 课程的学分,属性必修学分或选修学分决定课程的学分属性值;
F(系部编号和课程编号) = 开课学院;
总分数 = 学生(学号)对应课程(选课)表的所有课程成绩之和;
平均分 = 总分数除以学生(学号)对应课程(选课)表的所有选修课程的数量;
F(必修课或选修课)= 课程性质。

写于2013-04-09 22:14

发布了40 篇原创文章 · 获赞 0 · 访问量 1531

猜你喜欢

转载自blog.csdn.net/zhoumoon/article/details/104941459