开发者

Which tables should be created to store all the kinds of files for online application?

I new in database design.

I have a question with my own few solution, what do you think?

Which tables should be created for all the kinds files that stored in my online store (images, attached email files, text files for store email body, etc.) ?

option 1: use seperate table for files types

files{
id
files_types_id FK
file_path
file_extension
}

files_types
id
type_name (unique)
}

option 2: use bool field for each file type

f开发者_高级运维iles{
id
file_path
file_extension
is_image_main
is_image_icon
is_image_logo
is_pdf_file
is_text_file
}

option 3: use one ENUM field 'file_type' for each file type

files{
id
file_path
file_extension
file_type (image_main,image_icon,image_logo,image_main,pdf,text) **enum**
}

Thank you, Yosef


I would go with option 1 -- it's the "classic" fully normalized form.

I think of option 3 as the "poor man's normalization" -- the column is still constrained to the limited set of types, but you don't make the list of possible types available to database users. (In SQL Server, this would be done with a CHECK constraint.) Depending on your project and the (lack of) relevance of the data this can be worth doing, but "file type" information is useful and important and I wouldn't want to hide it.

To be complete, I'll toss in Option 4: create one table for every type of file:

files_text{ 
id 
file_path 
file_extension 
} 

files_pdf{ 
id 
file_path 
file_extension 
} 

files_image_main{ 
id 
file_path 
file_extension 
} 

etc.

This structure too can have its place, but it is generally horrible design, and you are wise not to have listed it. (Hmm, what does that make me?)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜