Domanda

I don't understand how to normalize a db table to 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. Am I right?

È stato utile?

Soluzione

You may keep separate tables for FileType, PType, and Keywords. For example, FileType has two columns - id and type. Similarly for Ptype and Keyword.

Proceeding further, Directory : FileName is a 1:N relation. So there will be a Directory table, and a FileName table with directory id as foreign key.

FileName : Keyword and FileName : FileType are N:N relations. I assume FileName : FileType is N:N because a file may be a zipped movie (archive + movie).

Not sure if FileName : PType is N:N. Depends on your use case though. I see it as 1:N. FileName can be freeware or shareware, not both. 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? 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.

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

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

filename_ptype

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

If filename can have only one ptype, then add ptype_id to filename table as foreign key. No need for filename_ptype.

filename_filetype

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

ptype

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

keyword

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

filetype

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

filetype's possible values are: image, archive, movie, audio, etc.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top