简体   繁体   English

如何将数据表标准化为3NF

[英]How to normalize data table to 3NF

I don't understand how to normalize a db table to 3NF? 我不明白如何将数据库表标准化为3NF?

FileName    FileName
Directory   Directory
FileType    FileType (Image, Archive, Movie)
PType           Freeware or shareware (need to be buyed)
UploadedDateTime Uploaded date time 
CheckedDateTime Checked date time
FileSize    size of file
Keywords    like: family, home, work, etc (something like tags)

As I understand we need to create 3 additional tables (for fileTypes, for PTypes and for Keywords) and 3 connection tables. 据我了解,我们需要创建3个其他表(用于fileTypes,PTypes和关键字)和3个连接表。 Am I right? 我对吗?

You may keep separate tables for FileType, PType, and Keywords. 您可以为FileType,PType和关键字保留单独的表。 For example, FileType has two columns - id and type. 例如,FileType有两列-id和type。 Similarly for Ptype and Keyword. 对于Ptype和关键字也是如此。

Proceeding further, Directory : FileName is a 1:N relation. 进一步,Directory:FileName是一个1:N关系。 So there will be a Directory table, and a FileName table with directory id as foreign key. 因此,将有一个Directory表和一个FileName表,其中目录ID为外键。

FileName : Keyword and FileName : FileType are N:N relations. FileName:关键字和FileName:FileType是N:N关系。 I assume FileName : FileType is N:N because a file may be a zipped movie (archive + movie). 我假设FileName:FileType为N:N,因为文件可能是压缩电影(存档+电影)。

Not sure if FileName : PType is N:N. 不知道FileName:PType是否为N:N。 Depends on your use case though. 但是取决于您的用例。 I see it as 1:N. 我认为它是1:N。 FileName can be freeware or shareware, not both. FileName可以是免费软件或共享软件,不能同时使用。 A simple foreign key relation would suffice here, no need for "connection" tables. 一个简单的外键关系就足够了,不需要“连接”表。

I assume dates will be attributes (columns) of FileName and Directory tables, wouldn't they? 我假设日期将是FileName和Directory表的属性(列),不是吗? If the dates are derived for Directory (max date of all FileNames in that directory), you will not need that column in Directory table, since it is calculated from other fields. 如果日期是从目录导出的(该目录中所有FileName的最大日期),则您不需要目录表中的该列,因为它是从其他字段中计算出来的。

I hope these are enough for you to get started. 我希望这些足以让您入门。

Update: 更新:

FileName 文档名称

+----+----------+-------+------+------------------+
| id | filename | dates | size | directoryid (FK) |
+----+----------+-------+------+-------------+----+

Directory 目录

+----+---------+-------+------+
| id | dirname | dates | size |
+----+---------+-------+------+

dates are not required if derived from filename table 如果从文件名表派生,则不需要日期

size are not required if derived from filename table 如果从文件名表派生,则不需要大小

filename_keyword filename_keyword

+-----+-------------+-----------------+
| id  | fileid (FK) |  keywordid (FK) |
+-----+-------------+-----------------+

filename_ptype filename_ptype

+----+-------------+--------------+
| id | fileid (FK) | ptypeid (FK) |
+----+-------------+--------------+

If filename can have only one ptype, then add ptype_id to filename table as foreign key. 如果filename只能有一个ptype,则将ptype_id添加到文件名表中作为外键。 No need for filename_ptype. 不需要filename_ptype。

filename_filetype filename_filetype

+----+-------------+-----------------+
| id | fileid (FK) | filetypeid (FK) |
+----+-------------+-----------------+

ptype ptype

+----+-------+
| id | ptype |
+----+-------+

keyword 关键词

+----+---------+
| id | keyword |
+----+---------+

filetype 文件类型

+----+----------+
| id | filetype |
+----+----------+

filetype's possible values are: image, archive, movie, audio, etc. 文件类型的可能值为:图像,档案,电影,音频等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM