任務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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章