问题描述
我有一个表的列表,即学生,老师,工作人员,部门。等等,每个表都有特定的注释。现在表中的一个记录可以有一个或多个注释,显示它是从任何表到注释表的一对多关系。我不知道什么最好的方法是将评论表与每个这些。如果我把外键从注释表中的每个表,这将像40-50字段,取决于否。的表。其次,如果我将外键从这些表中的每一个添加到备注表,它将像重复整行只为第二个备注外键?类似地,如果我只使用每个表中的一个字段作为注释,我实际上只是在一个文本字段中存储行。关于如何实现高效解决方案的任何建议?
I have a list of tables i.e. student, teacher, staff, dept. and so on and each of these tables have comments specific to them. Now one record in a table can have one or many comments that shows it's a one to many relation from any table to comments table. I don't know what the best way is to relate comments table to each of these. If I put foreign key from comments table to each of these tables, it will be like 40-50 fields depending on no. of tables. Secondly if I add foreign key from each of these tables to remarks table, it will be like repeating whole row just for the second remarks foreign key? Similarly if I use just one field in each table as comments, I will be actually storing rows in just one text field. Any suggestions on how to achieve efficient solution?
推荐答案
让我们假设你的表(学生,老师,一个名为Id的int主键。
Lets assume that your tables (student, teacher, staff, dept) all have a int primary key named Id.
对于您的注释表,您可以创建一个表。
For your comments table you could create a table.
Id int
CommentType enum (student, teacher, staff, dept)
LinkId int
Comment
注释中的一行可能如下所示
A row in Comments might look like this
1,'Student',347,'text'
这篇关于如何将一个表与多个不同的表相关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!