我应该使用“RecordID”吗?作为列名?

发布于 2024-10-20 23:12:43 字数 561 浏览 2 评论 0原文

我正在创建一个包含五个部分的在线应用程序。每个部分都有自己的表格。我们将这些部分称为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁月如刀 2024-10-27 23:12:43

我总是将我的 id 列命名为 id,表名前缀足以知道我正在谈论的 id。

在另一个主题中,您的 SECTION 表似乎具有完全相同的结构,为什么不只使用一个带有 number 列或类似内容的表?

回复评论:通过

SECTION
id - pk
ApplicationID - fk
name

QUESTION
id - pk
text

SECTION_QUESTION
id - pk
SectionID  - fk
QuestionID - fk

ANSWER
id - pk
SectionQuestionID - fk
text

这种方式,您可以创建各种问题,甚至可以在各个部分之间共享一些问题。 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 :

SECTION
id - pk
ApplicationID - fk
name

QUESTION
id - pk
text

SECTION_QUESTION
id - pk
SectionID  - fk
QuestionID - fk

ANSWER
id - pk
SectionQuestionID - fk
text

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 into ANSWER which is associated to SECTION_QUESTION instead of QUESTION this way you can know exactly in which section the answer was made.

I hope my proposition is clear.

尹雨沫 2024-10-27 23:12:43

我会采用这种结构:

Records - TABLE  
RecordID- int - pk  
SectionID int - fk
ApplicationID - fk  
Answer1 - text  
Answer2 - text  

Sections - TABLE
SectionId int - pk
SectionSequence int

您正在复制一个结构 - 如果这种结构发生变化(比如说您需要添加一列),您需要申请更改到多个表。 DRY 也适用于数据库。

I would go with this structure:

Records - TABLE  
RecordID- int - pk  
SectionID int - fk
ApplicationID - fk  
Answer1 - text  
Answer2 - text  

Sections - TABLE
SectionId int - pk
SectionSequence int

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.

我很OK 2024-10-27 23:12:43

第一件事是为什么你有section1和section2作为两个不同的表?您可以将它们合并到带有附加列 sectionIDsectionTitle 的单个表中。

然后,您的 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 and sectionTitle.

Then, your sectionID will be pk in the table and you do not need to use the column RecordID 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文