简体   繁体   中英

User database schema - over normalization or not?

I'm trying to create a user's database schema. I could consider "user" entity like a object with its properties, like so:

  • Users(table)
    • id
    • firstname
    • lastname
    • email
    • password
    • salt
    • description (text)
    • category (tinyint - foreign keys)
    • sub_category (tinyint - foreing keys)
    • status (varchar, active, banned, waiting (waiting for approval))
    • created (datetime)
    • edited (datetime)
    • deleted (datetime)

Otherwise I could separate description, into users_description table (1-1 relationship), category in user_category(1-1), users_status(1-1), users_datetime(1-1) (for created, edited...) and join them with a join.

Which form is better? I think than second hypothesis is "over normalized", in theory is better but in practically doesn't. I use Mysql and php.

Your schema is a good list of things that are sometimes "overnormalized".

Do not normalize "continuous" things, such as DATETIME , numbers, floats, etc. Some day you may need to fetch, say, the rows within some datetime range; normalization would make that clumsy and inefficient.

Things like "status" and "flags" and "yes/no", etc are often better handled with a simple ENUM .

Assuming "category" (and maybe "sub-category") has some other information associated with it, it is probably fine to normalize it. If it is a "many-to-many" relationship between users and categories, then you need 2 extra tables, and it is not really "normalization" but a "relationship". (You mentioned 1-1; I suspect that was a mistake.)

description TEXT -- This smells like a field that is never duplicated, so normalization will neither save space nor simplify changing it. Don't normalize.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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