我应该使用“RecordID”吗?作为列名?
我正在创建一个包含五个部分的在线应用程序。每个部分都有自己的表格。我们将这些部分称为 SECTION1、SECTION2 等。将有一个名为 APPLICATIONS 的主表。该表中的第一列是 ApplicationID。
超快的服务器上只会有几千条记录,因此我想将注意力集中在表和关系的可读性上,而不是如果我在生病之前进行非规范化,我可以节省多少处理能力。
以下是我认为应该如何命名和构建表格的方式。您能确认这是最具可读性的方法吗?过去,我曾有效地做到这一点。但是,我想看看是否有一些简单的改进或想法可以集成。从一到十,这种表/列命名方法的可靠性如何?
APPLICATIONS - TABLE
ApplicationID - pk
SECTION1 - TABLE
RecordID- int - pk
ApplicationID - fk
Answer1 - text
Answer2 - text
SECTION2 - TABLE
RecordID- int - pk
ApplicationID - fk
Answer1 - text
Answer2 - text
I am creating an online application with five sections. Each section will have its own table. Let's call those sections SECTION1, SECTION2, etc. There will be a main table named APPLICATIONS. The first column in that table will be ApplicationID.
There will only be a few thousand records on super fast servers, so I want to focus my attention on table and relationship readability, not on how much processing power I might be able to save if I de-normalize till I am sick.
Here's how I am thinking I should name and structure the tables. Can you confirm this is the most readable method? In the past, I have done this effectively. But, I want to see if there are some easy improvements or ideas to integrate. On a scale of one to ten, how solid is this method of table/column naming?
APPLICATIONS - TABLE
ApplicationID - pk
SECTION1 - TABLE
RecordID- int - pk
ApplicationID - fk
Answer1 - text
Answer2 - text
SECTION2 - TABLE
RecordID- int - pk
ApplicationID - fk
Answer1 - text
Answer2 - text
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我总是将我的 id 列命名为 id,表名前缀足以知道我正在谈论的 id。
在另一个主题中,您的 SECTION 表似乎具有完全相同的结构,为什么不只使用一个带有
number
列或类似内容的表?回复评论:通过
这种方式,您可以创建各种问题,甚至可以在各个部分之间共享一些问题。
SECTION_QUESTION
关联表映射问题和部分之间的关系。然后,您将答案存储到与SECTION_QUESTION
关联的ANSWER
中,而不是与QUESTION
相关联,这样您就可以准确地知道答案是在哪个部分中做出的。我希望我的提议是明确的。
I always name my id columns just id, the table name prefixed is enough to know that id I'm talking about.
In an other topic, your SECTION table seems to have the exact same structure, why not using only one table with a
number
column or something like this ?in response to the comments :
This way you can create your various questions, even share some questions between sections. The
SECTION_QUESTION
association table map the relation between a question and a section. Then you store the answers intoANSWER
which is associated toSECTION_QUESTION
instead ofQUESTION
this way you can know exactly in which section the answer was made.I hope my proposition is clear.
我会采用这种结构:
您正在复制一个结构 - 如果这种结构发生变化(比如说您需要添加一列),您需要申请更改到多个表。 DRY 也适用于数据库。
I would go with this structure:
You are duplicating a structure - if this changes (say you need to add a column), you need to apply to change to several tables. DRY applies to databases too.
第一件事是为什么你有section1和section2作为两个不同的表?您可以将它们合并到带有附加列
sectionID
和sectionTitle
的单个表中。然后,您的
sectionID
将在表中 pk,并且您不需要根据您的设计使用RecordID
列。这是根据我对你的问题的理解,除非你有任何具体原因保留第 1 节和第 2 节表。
编辑 - @Oded 的答案结构更好。
First thing is why do you have section1 and section2 as two different tables? you can merge them into single table with an addition column
sectionID
andsectionTitle
.Then, your
sectionID
will be pk in the table and you do not need to use the columnRecordID
as per your design.This is as per my understanding from your question, unless you have any specific reason to keep section1 and section2 tables.
EDIT - The answer from @Oded is much better structured.