学校的数据库架构

时间:2011-03-29 21:29:44

标签: sql-server database-design database-schema

以下是创建数据库所需的数据库查询:

create table Area
(
AreaId int primary key identity(1,1),
Name nvarchar(64) not null
)

create table Level
(
LevelId int primary key identity(1,1),
Name nvarchar(32) not null,
Principle nvarchar(512) not null
)

create table Subject
(
SubjectId int primary key identity(1,1),
AreaId int foreign key references Area(AreaId),
LevelId int foreign key references Level(LevelId),
Name nvarchar(32) not null,
Abbreviation nvarchar(16)
)

create table StaffType
(
StaffTypeId int primary key identity(1,1),
Name nvarchar(64) not null
)

create table Staff
(
StaffId int primary key identity(1,1),
StaffTypeId int foreign key references StaffType(StaffTypeId),
Name nvarchar(128) not null,
LastNameFather nvarchar(256) not null,
LastNameMother nvarchar(256) not null,
DateOfBirth datetime,
PlaceOfBirth nvarchar(256),
Sex nvarchar(8) not null,
Carnet nvarchar(64),
Telephone nvarchar(64),
MobilePhone nvarchar(64),
Address nvarchar(256),
FatherName nvarchar(256),
MotherName nvarchar(256),
FatherContactNumber nvarchar(64),
MotherContactNumber nvarchar(64),
FatherPlaceOfWork nvarchar(64),
MotherPlaceOfWork nvarchar(64),
DateOfHiring datetime,
YearsOfService int,
Formation nvarchar(128)
)

create table Grade
(
GradeId int primary key identity(1,1),
Name nvarchar(32) not null,
LevelId int foreign key references Level(LevelId),
Observation nvarchar(256)
)

create table GradeInstance
(
GradeInstanceId int primary key identity(1,1),
StaffId int foreign key references Staff(StaffId),
GradeId int foreign key references Grade(GradeId),
Name nvarchar(32) not null,
Year datetime
)

create table Student
(
StudentId int primary key identity(1,1),
RUDE int,
Name nvarchar(64) not null,
LastNameFather nvarchar(256) not null,
LastNameMother nvarchar(256) not null,
DateOfBirth datetime not null,
PlaceOfBirth nvarchar(128),
Sex nvarchar(8),
Carnet nvarchar(32),
Telephone nvarchar(64),
MobilePhone nvarchar(64),
Address nvarchar(256),
FatherName nvarchar(512),
MotherName nvarchar(512),
FatherMobilePhone nvarchar(64),
MotherMobilePhone nvarchar(64),
FatherProfession nvarchar(64),
MotherProfession nvarchar(64),
FatherPlaceOfWork nvarchar(256),
MotherPlaceOfWork nvarchar(256),
Observations nvarchar(3000)
)

create table StudentInstance
(
StudentInstanceId int primary key identity(1,1),
GradeInstanceId int foreign key references GradeInstance(GradeInstanceId),
StudentId int foreign key references Student(StudentId)
)

create table StudentGradeReport
(
StudentGradeReportId int primary key identity(1,1),
StudentInstanceId int foreign key references StudentInstance(StudentInstanceId),
SubjectId int foreign key references Subject(SubjectId),
FirstTrimester int,
SecondTrimester int,
ThirdTrimester int,
FinalGrade int
)

如果您发现 应为空检查的属性,请忽略它。我已经和客户讨论了这个问题,如果最终用户选择的那样,他们希望某些事情留空。

我在设计这个数据库时的主要关注点是如何将学生与现在和现在的成绩联系起来,但是保留了前几年的成绩,并设法查看他在2009年获得的成绩。看到了吗?

我认为我做得很好,但你永远不知道 - 这里的hivemind可能会找到一个缺陷,我会喜欢一些反馈。

  • 不再使用SQLite,而是使用MSSQL。
  • 我试图尽可能地规范化数据库,但不是虔诚地,只是为了让它“点击”。
  • 在学生之前,与课堂(成绩)实例直接相关。现在我创建学生的“实例”并将它们分配给课堂(成绩)实例。每个实例都有一个日期,说明它属于哪一年。这有助于我记录前几年没有肮脏的黑客行为。

1 个答案:

答案 0 :(得分:1)

create table Area
(
AreaId int primary key identity(1,1),
Name nvarchar(64) not null
)

“名称”应该是独一无二的。

create table Level
(
LevelId int primary key identity(1,1),
Name nvarchar(32) not null,
Principle nvarchar(512) not null
)

“名称”应该是独一无二的。

create table Subject
(
SubjectId int primary key identity(1,1),
AreaId int foreign key references Area(AreaId),
LevelId int foreign key references Level(LevelId),
Name nvarchar(32) not null,
Abbreviation nvarchar(16)
)

其中一项或多项适用的可能性很大。没有代表性的样本数据就无法分辨。

  • 集合{AreaId,LevelId}应该是 唯一的。
  • “名称”应该是独一无二的。
  • “缩写”应该是独一无二的。

我的时间不多了。

create table StaffType
(
StaffTypeId int primary key identity(1,1),
Name nvarchar(64) not null
)

“名称”应该是独一无二的。

如果我有时间的话,等等。