• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

数据库设计有关问题。崩溃ING.

mysql 搞代码 7年前 (2018-06-01) 127次浏览 已收录 0个评论

数据库设计问题。崩溃ING…
学生作业管理系统
主要功能:
1.教师可以通过   所教班级(多个班)或所教科目   .布置作业内容
2.学生通过所学科目.查看尚未完成作业   提交作业
3.教师通过所教班级.或点击已经提交的作业查看   批改作业
4.学生通过科目.查看提交的作业的分数.

主要表:   1.学生   2.教师   3.班级   4.科目   5.作业

设计表的难点:
1.课程是可以增减的
2.所教班级不止一个班??
3.教师所教科目不止一个,并且教的科目每年可能会变.
4.班级的课程每年也会变

提问:
本来我的关系是这样建的

教师表:TID   TNAME…
课程表:SID   SNAME…
班级表:CID   CNAME…
临时表:TID   SID   CID

后来朋友建议我将   课程ID   字段内容设计成:2007-J-02-11    
意思代表   2007年的课程   名字叫java   属于02教学组   属于11班级组
 
请问这样设计字段后该如何建立关系表啊.

——解决方案——————–
你的表的结构可以,你朋友的不好
——解决方案——————–
1、教师表 与 课程表 建立一个对应表 A(一个教师可以教多门课程 1:N)
2、学生表 与 A 建立一个对应表 B (学生选课的同时,也于老师建立了对应关系)
3、学生表 与 班级表 建立一个对应表 C (解决因年度变化,班级与学生多对多的情况)
4、在作业表里将科目编码作为外键(一个科目可能有多种作业)

以上想法,供参考。
——解决方案——————–
create table class #班级
(
ID smallint(5) unsigned not null auto_increment primary key,
name varchar(20) not null default ' ',
students tinyint(3) unsigned not null default 0 #学生数量
)
engine=MyISAM default charset=utf8;

create table subject #科目
(
ID tinyint(3) unsigned not null auto_increment primary key,
name varchar(20) not null default ' '
)
engine=MyISAM default charset=utf8;

create table teacher #教师
(
ID smallint(5) unsigned not null auto_increment primary key,
name varchar(20) not null default ' '
)
engine=MyISAM default charset=utf8;

create table relation #教师与所教班级、科目的对应关系
(
ID smallint(5) unsigned not null auto_increment primary key,
class smallint(5) not null default 0,
SID text #科目ID列表,例“1,2,3”
)
engine=MyISAM default charset=utf8;

create table student #学生
(
ID mediumint(8) unsigned not null auto_increment primary key,
name varchar(20) not null default ' ',
CID smallint(5) not null, #班级ID
SID text, #科目ID列表,例“1,2,3”
index index_CID (CID)
)
engine=MyISAM default charset=utf8;

create table homework #作业
(
ID mediumint(8) unsigned not null auto_increment primary key,
TID smallint(5) unsigned not null, #教师ID
CID smallint(5) unsigned not null, #班级ID
SID tinyint(3) unsigned not null, #科目ID
text text, #内容
index index_CID_SID (CID, SID)
)
engine=MyISAM default charset=utf8;

create table homework_submited #提交的作业
(
ID mediumint(8) unsigned not null auto_increment primary key,
HID mediumint(8) unsigned not null, #作业ID
SID mediumint(8) unsigned not null, #学生ID
score tinyint(3) unsigned not null, #得分
index index_HID (HID)
)
engine=MyISAM default charset=utf8;


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:数据库设计有关问题。崩溃ING.

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址