表的规范化

发布于 2024-12-11 09:38:57 字数 850 浏览 0 评论 0原文

我正在尝试使用 VB.Net 和 MySQL 作为数据库创建一个简单的注册程序。这是我的基本信息简单表格

在此处输入图像描述

但是,我正在尝试提高我在表格标准化方面的基本知识这就是为什么我将日期字段分开以避免(比方说在一天内)重复插入相同的日期。我的意思是,当一天有 50 个人注册时,它只会在 tblRegDate 表中添加单个日期(记录),而不是在表中添加 50 次。有什么办法可以做到这一点吗?在 VB.Net 和 MySQL 中可以吗?或者更确切地说,我应该添加或修改某些字段吗?或者我应该在VB.Net中设定一个条件?上表是我朋友教我的,但我发现它并没有消除冗余。请给我任何指示或引导我到有简单教程的网站。提前致谢!

这是我的 MySQL 代码:

CREATE TABLE tblInfo(
       Number INT AUTO_INCREMENT,
       LastName VARCHAR(45),
       FirstName VARCHAR(45),
       MiddleName VARCHAR(45),
       Gender ENUM(M,F),
       BirthDate DATE,
       PRIMARY KEY(Number));

CREATE TABLE tblRegDate(
       IDRegDate INT AUTO_INCREMENT,
       Date TIMESTAMP,
       Number INT,
       PRIMARY KEY(IDRegDate),
       FOREIGN KEY(Number) REFERENCES tblInfo(Number));

I am trying to create a simple Registration Program using VB.Net and MySQL for its database. Here's my simple table for the basic Information

enter image description here

However, I am attempting to improve my basic knowledge in normalization of table and that's why I separated the Date field to avoid, let say in one day, the repeated insertion of the same date. I mean, when 50 individuals registered in one day, it will simply add a single date(record) in tblRegDate table instead of adding it up for 50 times in a table. Is there any way to do this? Is it possible in VB.Net and MySQL? Or rather, should I add or modify some field? or should I make a condition in VB.Net? The table above is what my friend taught me but I discovered that it doesn't eliminate the redundancy. Kindly give me any instruction or direct me to site where there's a simple tutorial for this. Thanks in advance!

here's my MySQL codes:

CREATE TABLE tblInfo(
       Number INT AUTO_INCREMENT,
       LastName VARCHAR(45),
       FirstName VARCHAR(45),
       MiddleName VARCHAR(45),
       Gender ENUM(M,F),
       BirthDate DATE,
       PRIMARY KEY(Number));

CREATE TABLE tblRegDate(
       IDRegDate INT AUTO_INCREMENT,
       Date TIMESTAMP,
       Number INT,
       PRIMARY KEY(IDRegDate),
       FOREIGN KEY(Number) REFERENCES tblInfo(Number));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

七堇年 2024-12-18 09:38:57

正如我所看到的,在这种情况下,分隔单个字段没有任何优势。你会失去很多性能。

表规范化并不是没有任何冗余值。它更多的是关于“分离关注点”

另外,数据库中不要出现爆炸式的复杂性也很重要。单独的填充最终会出现在一个没有人能够理解的数据库中。

问题是:有更多关于注册的信息吗?例如网页、IP、......

您应该有两个表,例如“人员”和“注册”。那么你就会有两个语义不同的东西,不应该混淆。

您可以通过谷歌找到很多示例和信息。和维基百科
http://en.wikipedia.org/wiki/Database_normalization

As I see it in this case you don't have advanages of seperating a single field. You'll loose a lot of performance.

Table normalization isn't about don't having any redundant value. It's more about "Seperating the concerns"

Also it is important to not have an exploding complexity in your database. seperating single fills would end up in a database no one would be able to understand.

The Question is: Are there more informations on registration ? For Example Webpage, IP, .....

Than you should have two tables for example "Person" and "Registration". Then you would have two semantic different things which shouldn't be mixed up.

There are a lot of examples and information you can find via google. and wikipedia
http://en.wikipedia.org/wiki/Database_normalization

吃素的狼 2024-12-18 09:38:57

实际上,将时间戳与表分开并不是一个好主意。
您将需要另一个表,即 timeTable。它有两列 id 和 timestmap,您应该在 tblRegDate 表中引用此 id 作为外键。
外键是一个整数,大小为 4 个字节。另一方面,日期为 3 个字节。

因此,我建议您将日期保存在 tblRegDate 中,而不是保存在额外的表中

Actually it is not a good idea to seperate timestamp from the table.
You would need another table namely i.e timeTable. It would have two columns id and timestmap and you should reference this id in your tblRegDate table as foreign key.
Foreign key is an integer and has the size 4 bytes. Date on the other hand 3 bytes.

Therefore I would recommend you to keep date in your tblRegDate and not in a extra table

伴我老 2024-12-18 09:38:57

当您规范化数据库结构时,请始终牢记 ACID - http://en.wikipedia.org/wiki/ ACID

根据您拥有的字段,您应该将其保留为单个表。将注册日期分开并不是一个好的设计,因为您每次都必须进行查找。在现实生活中,如果您的应用程序始终按注册日期搜索或排序,则可以考虑对注册日期建立索引。

而且如果将 RegDate 表 FK 到用户表,效率也很低。

ps 另请记住,数据库规范化有 4 个级别。如果您是数据库设计的新手,您应该考虑学习如何将数据库设计从第一范式转移到第二范式,以及如何将第二范式转移到第三范式。

我们很少在现实生活中使用第四范式。交易系统通常在大多数时间停留在第三位。

希望这是有道理的。

When you normalize DB structures, always keep it mind of ACID - http://en.wikipedia.org/wiki/ACID

Based on the fields you have, you should just keep it as a single table. Separating out the registration date is not a good design because you'll have to do a look up every time. In real life, you can consider indexing the reg date if your app always search or sort by regdate.

And if you FK RegDate table to the user table, it is also not efficient.

p.s. Also keep in mind that there are 4 levels of DB normalization. If you are new to DB design, you should consider learning how to move a DB design from 1st to 2nd, and 2nd to 3rd normal forms.

We rarely use 4th normal form in real life situation. Transaction systems usually stay at 3rd most of the time.

Hope that make sense.

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