平时成绩记分系统代码实现过程v基础数据设计.docx
- 文档编号:5327679
- 上传时间:2022-12-15
- 格式:DOCX
- 页数:33
- 大小:535.35KB
平时成绩记分系统代码实现过程v基础数据设计.docx
《平时成绩记分系统代码实现过程v基础数据设计.docx》由会员分享,可在线阅读,更多相关《平时成绩记分系统代码实现过程v基础数据设计.docx(33页珍藏版)》请在冰豆网上搜索。
平时成绩记分系统代码实现过程v基础数据设计
平时成绩记分系统工程代码实现过程-基础数据设计
目录
1基础数据设计1
1.1概念模型设计1
1.2逻辑模型设计4
1.3物理模型9
1.4生成创建数据库的脚本12
1.5准备示范数据22
2常见错误22
2.1PowerDesigner部份或全部外键脚本没有生成22
2.2PowerDesigner生成的数据库脚本一片空白24
3小技巧25
3.1在创建数据表、数据库等对象时,注意不要使用关键字作为对象的名称。
25
图目录
图1.1PowerDesigner中设置数据模型的特性——菜单2
图1.2PowerDesigner中设置数据模型的特性——对话框3
图1.3基础数据概念模型4
图1.4概念模型转换为逻辑模型——菜单操作5
图1.5逻辑模型名称设置6
图1.6转换得到的逻辑模型6
图1.7学生与登录用户之间的关系7
图1.8基础数据的逻辑模型8
图1.9设置“学生”的主键8
图1.10确保所有的表都将会生成9
图1.11最终的逻辑模型9
图1.12逻辑模型转换为物理模型——菜单操作10
图1.13物理模型数据库类型及名称设置11
图1.14自动转换得到的物理模型11
图1.15更改数据库类型12
图1.16配置外键关联的实现类型13
图1.17创建数据库脚本——菜单13
图1.18设置脚本文件路径14
图2.1更改数据库类型23
图2.2更改外键关联的实现类型24
图2.3设置PowerDesigner数据库创建脚本的字符集25
代码目录
代码1.1基础数据表创建脚本15
基础数据管理(管理员业务)
在“平时成绩记分系统工程代码实现过程v1.0-用户登录.doc”中我们实现了一个基本的用户登录的功能。
但登录用户所提供的信息非常简单。
对于一个实际的应用系统来说,仅仅登录名和密码还远远不够往往还需要用户的姓名、联系方式等信息——对于教师来讲,可能还有职称等信息;对于学生来讲,可能还有班级、专业等信息——这将形成一个复杂的、紧密联系的数据集。
我们把这些暂时不涉及平时成绩记录的、稳定的数据称为基础数据,包括学生、班级和课程(教师数据暂不考虑),由管理员admin管理。
学生可以浏览与自己相关的这些基础数据。
1基础数据设计
我们用PowerDesigner来进行数据库的设计。
大致经过三个步骤:
1)概念模型设计
2)逻辑模型设计
3)物理模型设计
概念模型设计
为了使用继承的关系(学生继承于登录用户)以及复杂的数据联系,需要修改PowerDesigner概念模型的设置,即进行以下操作:
1)点击菜单“ToolsModelOptions…”
PowerDesigner中设置数据模型的特性——菜单
2)左边选择“ModelSettings”,右边点击“Notation”下拉框,选择“E/R+Merise”,再点击“OK”即可。
PowerDesigner中设置数据模型的特性——对话框
所设计的概念模型如下图所示:
基础数据概念模型
逻辑模型设计
逻辑模型可以从概念模型自动转化而得,在PowerDesigner中操作如下:
1)选取欲转换的概念模型(此处为“基础数据概念模型”),再选取菜单“”——“”,如下:
概念模型转换为逻辑模型——菜单操作
2)在对话框中输入逻辑模型名称
逻辑模型名称设置
3)点击“确定”,得到逻辑模型:
转换得到的逻辑模型
4)添加学生与登录用户之间的依赖关系,如图所示(注意“学生”方的基是“0..n”):
学生与登录用户之间的关系
5)得到逻辑模型,如下图:
基础数据的逻辑模型
6)手工将“学生”表“登录名”字段设为主键,同时将它改更加好听的名称:
“学号”,编码改为“studentId”。
如下图所示:
设置“学生”的主键
类似地,将“班级”中“专业编码”改为好听的“专业”,将“选修”及“班级可选修”中的“授课编码”改为“课程”,将“班级可选修”中的“班级编号”改为“班级”。
7)最后,确保所有的表都将会生成,特别是“登录用户”表需要手工设置。
具体的菜单操作为“Model”“Entities…”,对话框设置见下图标注:
确保所有的表都将会生成
最终得到的逻辑模型见下图:
最终的逻辑模型
物理模型
同样,物理模型可由逻辑模型自动转换而来。
操作如下:
1)菜单操作过程为:
“Tools”——“GeneratePhysicalDataModel…”,见下图。
逻辑模型转换为物理模型——菜单操作
2)在弹出的对话框中选择数据库类型,给出物理模型的名称
物理模型数据库类型及名称设置
3)得到物理模型
自动转换得到的物理模型
生成创建数据库的脚本
1)设置数据库类型。
菜单操作为“database”“ChangeCurrentDBMS…”,在弹出的对话框“DBMS”中选择正确的数据库类型。
注意,如果数据库类型即便为“MicrosoftSQLServer2005”,那么也要选择“MicrosoftSQLServer2000”。
更改数据库类型
2)配置外键关联的实现类型为“Declarative”。
菜单操作为“Model”“References…”:
配置外键关联的实现类型
3)如果数据库为SQLSERVER2005,那么需要按照第1步(更改数据库类型),将数据库类型改回为“MicrosoftSQLServer2005”。
4)生成脚本。
菜单操作为“Database”“GenerateDatabase…”:
创建数据库脚本——菜单
5)设置脚本文件路径:
设置脚本文件路径
6)点击“确定”后,生成的创建脚本如下:
代码1.1基础数据表创建脚本
ifexists(select1
fromsys.sysreferencesrjoinsys.sysobjectsoon(o.id=r.constidando.type='F')
wherer.fkeyid=object_id('SC')ando.name='FK_SC_SC_STUDENT')
altertableSC
dropconstraintFK_SC_SC_STUDENT
go
ifexists(select1
fromsys.sysreferencesrjoinsys.sysobjectsoon(o.id=r.constidando.type='F')
wherer.fkeyid=object_id('SC')ando.name='FK_SC_SC2_LECTURE')
altertableSC
dropconstraintFK_SC_SC2_LECTURE
go
ifexists(select1
fromsys.sysreferencesrjoinsys.sysobjectsoon(o.id=r.constidando.type='F')
wherer.fkeyid=object_id('class_sc')ando.name='FK_CLASS_SC_CLASS_SC_LECTURE')
altertableclass_sc
dropconstraintFK_CLASS_SC_CLASS_SC_LECTURE
go
ifexists(select1
fromsys.sysreferencesrjoinsys.sysobjectsoon(o.id=r.constidando.type='F')
wherer.fkeyid=object_id('class_sc')ando.name='FK_CLASS_SC_CLASS_SC2_STUDENTC')
altertableclass_sc
dropconstraintFK_CLASS_SC_CLASS_SC2_STUDENTC
go
ifexists(select1
fromsys.sysreferencesrjoinsys.sysobjectsoon(o.id=r.constidando.type='F')
wherer.fkeyid=object_id('student')ando.name='FK_STUDENT_STUDENT_C_STUDENTC')
altertablestudent
dropconstraintFK_STUDENT_STUDENT_C_STUDENTC
go
ifexists(select1
fromsys.sysreferencesrjoinsys.sysobjectsoon(o.id=r.constidando.type='F')
wherer.fkeyid=object_id('student')ando.name='FK_STUDENT_STUDENT_L_LOGINUSE')
altertablestudent
dropconstraintFK_STUDENT_STUDENT_L_LOGINUSE
go
ifexists(select1
fromsys.sysreferencesrjoinsys.sysobjectsoon(o.id=r.constidando.type='F')
wherer.fkeyid=object_id('studentClass')ando.name='FK_STUDENTC_CLASS_MAJ_MAJOR')
altertablestudentClass
dropconstraintFK_STUDENTC_CLASS_MAJ_MAJOR
go
altertableSC
dropconstraintPK_SC
go
ifexists(select1
fromsysobjects
whereid=object_id('SC')
andtype='U')
droptableSC
go
altertableclass_sc
dropconstraintPK_CLASS_SC
go
ifexists(select1
fromsysobjects
whereid=object_id('class_sc')
andtype='U')
droptableclass_sc
go
altertablelecture
dropconstraintPK_LECTURE
go
ifexists(select1
fromsysobjects
whereid=object_id('lecture')
andtype='U')
droptablelecture
go
altertableloginUser
dropconstraintPK_LOGINUSER
go
ifexists(select1
fromsysobjects
whereid=object_id('loginUser')
andtype='U')
droptableloginUser
go
altertablemajor
dropconstraintPK_MAJOR
go
ifexists(select1
fromsysobjects
whereid=object_id('major')
andtype='U')
droptablemajor
go
altertablestudent
dropconstraintPK_STUDENT
go
ifexists(select1
fromsysobjects
whereid=object_id('student')
andtype='U')
droptablestudent
go
altertablestudentClass
dropconstraintPK_STUDENTCLASS
go
ifexists(select1
fromsysobjects
whereid=object_id('studentClass')
andtype='U')
droptablestudentClass
go
/*==============================================================*/
/*Table:
SC*/
/*==============================================================*/
createtableSC(
studentIdvarchar(20)notnull,
lectureIdvarchar(30)notnull
)
go
declare@CurrentUsersysname
select@CurrentUser=user_name()
executesp_addextendedproperty'MS_Description',
'选修',
'user',@CurrentUser,'table','SC'
go
declare@CurrentUsersysname
select@CurrentUser=user_name()
executesp_addextendedproperty'MS_Description',
'学号',
'user',@CurrentUser,'table','SC','column','studentId'
go
declare@CurrentUsersysname
select@CurrentUser=user_name()
executesp_addextendedproperty'MS_Description',
'课程',
'user',@CurrentUser,'table','SC','column','lectureId'
go
altertableSC
addconstraintPK_SCprimarykeynonclustered(studentId,lectureId)
go
/*==============================================================*/
/*Table:
class_sc*/
/*==============================================================*/
createtableclass_sc(
lectureIdvarchar(30)notnull,
classNamevarchar(30)notnull
)
go
declare@CurrentUsersysname
select@CurrentUser=user_name()
executesp_addextendedproperty'MS_Description',
'记录该授课所面向的班级,为生成学生选修记录提供范本',
'user',@CurrentUser,'table','class_sc'
go
declare@CurrentUsersysname
select@CurrentUser=user_name()
executesp_addextendedproperty'MS_Description',
'课程',
'user',@CurrentUser,'table','class_sc','column','lectureId'
go
declare@CurrentUsersysname
select@CurrentUser=user_name()
executesp_addextendedproperty'MS_Description',
'班级',
'user',@CurrentUser,'table','class_sc','column','className'
go
altertableclass_sc
addconstraintPK_CLASS_SCprimarykeynonclustered(lectureId,className)
go
/*==============================================================*/
/*Table:
lecture*/
/*==============================================================*/
createtablelecture(
lectureIdvarchar(30)notnull,
lectureNamevarchar(100)null
)
go
declare@CurrentUsersysname
select@CurrentUser=user_name()
executesp_addextendedproperty'MS_Description',
'授课',
'user',@CurrentUser,'table','lecture'
go
declare@CurrentUsersysname
select@CurrentUser=user_name()
executesp_addextendedproperty'MS_Description',
'授课编码',
'user',@CurrentUser,'table','lecture','column','lectureId'
go
declare@CurrentUsersysname
select@CurrentUser=user_name()
executesp_addextendedproperty'MS_Description',
'授课名称',
'user',@CurrentUser,'table','lecture','column','lectureName'
go
altertablelecture
addconstraintPK_LECTUREprimarykeynonclustered(lectureId)
go
/*==============================================================*/
/*Table:
loginUser*/
/*==============================================================*/
createtableloginUser(
idvarchar(20)notnull,
passwordvarchar(50)null,
namevarchar(30)notnull,
telephonevarchar(50)null,
mobilephonevarchar(30)null,
emailvarchar(100)null,
addressvarchar(200)null,
zipCodevarchar(30)null,
contactvarchar(200)null
)
go
declare@CurrentUsersysname
select@CurrentUser=user_name()
executesp_addextendedproperty'MS_Description',
'登录用户',
'user',@CurrentUser,'table','loginUser'
go
declare@CurrentUsersysname
select@CurrentUser=user_name()
executesp_addextendedproperty'MS_Description',
'登录名',
'user',@CurrentUser,'table','loginUser','column','id'
go
declare@CurrentUsersysname
select@CurrentUser=user_name()
executesp_addextendedproperty'MS_Description',
'密码',
'user',@CurrentUser,'table','loginUser','column','password'
go
declare@CurrentUsersysname
select@CurrentUser=user_name()
executesp_addextendedproperty'MS_Description',
'姓名',
'user',@CurrentUser,'table','loginUser','column','name'
go
declare@CurrentUsersysname
select@CurrentUser=user_name()
executesp_addextendedproperty'MS_Description',
'电话',
'user',@CurrentUser,'table','loginUser','column','telephone'
go
declare@CurrentUsersysname
select@CurrentUser=user_name()
executesp_addextendedproperty'MS_Description',
'手机',
'user',@CurrentUser,'table','loginUser','column','mobilephone'
go
declare@CurrentUsersysname
select@CurrentUser=user_name()
executesp_addextendedproperty'MS_Description',
'email',
'user',@CurrentUser,'table','loginUser','column','email'
go
declare@CurrentUsersysname
select@CurrentUser=user_name()
executesp_addextendedproperty'MS_Description',
'地址',
'user',@CurrentUser,'tab
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 平时 成绩 记分 系统 代码 实现 过程 基础 数据 设计