Mysql - 一个简单的数据库设计问题

San*_*ath 5 mysql database-design

假设我Tutors有谁采取online webclasses和创造learning packs.双方online webclasseslearning packs可以通过额定students终于tutor's评级是对他的所有收视率的简单平均classespacks.

这是我们当前Ratings表的表结构-

CREATE TABLE IF NOT EXISTS `Ratings` (
  `id_rating` int(10) unsigned NOT NULL auto_increment,
  `id_teacher` int(10) unsigned default NULL COMMENT 'the teacher who created the class/pack',
  `id_lp` int(10) unsigned default NULL  COMMENT 'the id of the learning pack',
  `id_wc` int(10) NOT NULL default '0' COMMENT 'the id of the webclass',
  `id_user` int(10) unsigned NOT NULL default '0' COMMENT 'the user who has rated',
  `rate` int(10) unsigned NOT NULL default '0',
  `cdate` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `udate` timestamp NULL default NULL,
  PRIMARY KEY  (`id_rating`),
  KEY `Ratings_FKIndex1` (`id_user`),
  KEY `id_lp` (`id_lp`),
  KEY `id_wc` (`id_wc`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Run Code Online (Sandbox Code Playgroud)

目前,类和包等级都输入到同一个表中(id_wc并相应id_lp地输入 - 一个输入,另一个输入NULL每个评级记录).

所以,我的问题是 -
这种架构是正确的还是更好地保持classpack评级分开?为什么或者为什么不?Rating对于两者classpack评级,我需要完全相同数量的表字段.

我想,如果要单独找到类和包的评级,那么单独的表会减少要查找的记录数.但是,因为在我们的情况下只需要导师评级(涉及课程和包),这就是为什么所有评级都被放在一起的原因.

che*_*vim 0

如果您认为最终会得到更多需要评级的实体,那么您需要创建一些更通用的东西(并且不太适合数据库哲学)。

ratings
-------
id
voterClass
voterId
subjectClass
subjectId
vote
date(s)
Run Code Online (Sandbox Code Playgroud)

通过使用这种设计,您会忘记 FK 和引用完整性。但它非常灵活,并且使用正确的索引它具有很强的可扩展性。此外,当实体(主题)被删除时,投票仍然存在。这种设计使您免于重复字段和表。