我有一个包含多个表的数据库。
此多个表与单个名称相关,例如..
Table 1 contains name of the person, joined date,position,salary..etc
Table2 contains name of the person,current projects,finished,assigned...etc
Table 3 contains name of the person,time sheets,in,out,etc...
Table 4 contains name of the person,personal details,skill set,previous experiance,...etc所有表包含的不止50000 names,以及它们的详细信息。
所以我的问题是,所有的表都包含与一个名称相关的信息,比如说Jose20856,这个名称是所有4个表的唯一索引。当我搜索Jose20856时,所有四个表都会给出结果并输出到前端软件/html。那么我需要保留多个表还是合并到一个表中??
如果是这样
CASE 1
Single table -> what are the advantages? will result will be faster? what about the system resource usage?
CASE 2
Multiple table ->what are the advantages? will result will be faster? what about the system resource usage?由于我是MySQL的新手,我希望您能给我宝贵的意见,让我继续前进
发布于 2011-01-09 01:04:11
在web上阅读有关数据库规范化的内容。
例如,http://en.wikipedia.org/wiki/Database_normalization
我认为您甚至可以向其中添加更多的表。这完全取决于数据和关系。
Table1 = users incl. userdata
Table2 = Projects (if multiple users work on the same project)
Table3 = Linking user to projects (if multiple users work on the same project)
Table4 = Time spent? Contains the links to the user and to the project.我认为您的表4可以合并到表1中,因为它还包含特定于1个用户的数据。
你可能还能做更多的事情,但正如前面所说的,这一切都取决于它们之间的关系。
发布于 2011-01-09 01:12:42
您可以将这些内容合并到一个表中,但前提是这是有意义的。很难说您的表中的关系是一对一还是一对多,但似乎是一对多。例如,表1中的单个员工应该能够在其他表中拥有多个项目、技能和时间表。这些都是一对多的关系。
所以,保持多表的设计。您还应该考虑对员工而不是姓名使用基于整数的主键。在其他表中使用此pkey作为fkey,您将看到性能改进。(还要考虑当您想要更改名称时需要做的工作量。您必须更改所有表中的所有名称。如果按照上面的建议使用代理键int pkey,则只需更新一行。)
发布于 2011-01-09 01:25:32
joined date,position,salary和列personal details,skill set,previous experiance,那么将这些列移动到不同的表中是有意义的,因为这将(可能)提高访问那些最常用的列的性能。在MySQL中,这一点在TEXT和BLOB列中尤其明显,因为它们与其他文件分开存储,因此访问它们需要更多时间。最后但并非最不重要。
Additional reading aboout MySQL partitioning (有点过时,因为MySQL 5.5增加了一些新功能)
https://stackoverflow.com/questions/4635005
复制相似问题