學生成績管理系統(tǒng) 數(shù)據(jù)庫設計(內含sql查詢語句)【研究分析】
屬于
年齡
性別
學 生
1
課程號
學號
選課
課程名
課 程
m n
姓名
學時
N1
ISA
N4
學分
開課學期
班號
班 級
1
選修課
必修課
開設
專 業(yè)
編
號
專 業(yè)
屬于
N2
系名稱
系編號
1
1
N3
開設
專業(yè)名
系
1
create database 學生成績管理系統(tǒng)
go
use 學生成績管理系統(tǒng)
go
create table 系(
系編號 char(15) NOT NULL UNIQUE,
系名稱 char(20) NOT NULL UNIQUE,
constraint 系pk primary key(系編號,系名稱)
)
create table 專業(yè)(
專業(yè)編號 char(15) NOT NULL UNIQUE,
專業(yè)名 char(20) NOT NULL UNIQUE,
系編號 char(15) NOT NULL,
constraint 專業(yè)pk primary key(專業(yè)編號,專業(yè)名),
constraint FK_系_專業(yè) foreign key(系編號) references 系(系編號)
)
create table 班級(
班號 char(15) NOT NULL UNIQUE,
班名 char(20) NOT NULL UNIQUE,
專業(yè)編號 char(15) NOT NULL,
constraint 班級pk primary key(班號,班名),
constraint FK_專業(yè)_班級 foreign key(專業(yè)編號) references 專業(yè)(專業(yè)編號)
)
create table 學生(
學號 char(15) NOT NULL UNIQUE,
姓名 char(20) NOT NULL,
性別 char(5),
年齡 int,
班號 char(15),
constraint 學生pk primary key(學號),
constraint 性別ck check(性別='男' or 性別='女'),
constraint 年齡ck check(年齡>0 and 年齡<90),
constraint FK_班級_學生 foreign key(班號) references 班級(班號)
)
create table 課程(
課程號 char(15) NOT NULL UNIQUE,
課程名 char(20) NOT NULL,
學時 int,
學分 float,
開課學期 char(20),
課程性質 char(10),
constraint 課程pk primary key(課程號),
constraint 課程性質ck check(課程性質='選修' or 課程性質='必修')
)
create table 選課(
學號 char(15) NOT NULL,
課程號 char(15) NOT NULL,
成績 float,
constraint 選課pk primary key(學號,課程號),
constraint 成績ck check(成績>=0 and 成績<=100),
constraint FK_學生_選課 foreign key(學號) references 學生(學號),
constraint FK_課程_選課 foreign key(課程號) references 課程(課程號)
)
create view 學生成績(學號,姓名,班級,課程名,成績,學分績點)
AS
select 選課.學號,姓名,班級=(select 班名 from 班級 where 班號=(
select 班號 from 學生 where 學生.學號=選課.學號)),
課程名,成績,學分績點=
case
when 成績>=90 then 學分*4
when 成績<90 and 成績>=85 then 學分*3.5
when 成績<85 and 成績>=80 then 學分*3
when 成績<80 and 成績>=75 then 學分*2.5
when 成績<75 and 成績>=70 then 學分*2
when 成績<70 and 成績>=65 then 學分*1.5
when 成績<65 and 成績>=60 then 學分*1
when 成績<60then 學分*0
end
from 學生,課程,選課
where 學生.學號=選課.學號 and 課程.課程號=選課.課程號
3
技術l類別