mysql - Separate tables or differentiating fields? -
i have 2 websites run both subscription-based service. both of sites allow subscribers make "subusers" can use subscriptions have different login (for security , logging purposes). each website has different way of implementing this.
separate table
the first system has separate table called subsusers
. each subuser linked (via foreign key) user
. setup requires additional code in login scripts anywhere user info needs accessed.
differentiating fields
the other site not have subusers
table. instead, field in users
table points user "parent", signifying subuser. requires less coding in login , user info scripts.
both of these setups functional , work fine. wondering though: advantages , disadvantages of each (speed, coding, hassle)?
option 1:
pros:
- if set keys correctly, can implement cascading deletes/updates more easily. if users cancels, example, deleting them automatically delete other users, via foreign key. if need update user account , have changes affect subusers, that's straightforward here
- if data requirements between users , subusers substantially different, avoid lot of unused fields otherwise required in 1 table solution
cons:
- basically described and
- what happens if subuser becomes user? or user becomes subuser? how keep application logic tidy users members of both user table , subuser table?
option 2:
pros 1. it's easier manage type of scenario described above, user might become subuser or vice versa.
- the application logic simple , straightforward, if don't have several levels (sub-subusers , sub-sub-subusers, example)
cons
- if have multiple levels (and if have variable number of levels) can kind of pain
- if user data , subuser data radically different , find inserting ton of null values every user , subuser, indication schema needs changed (either user-subuser setup, or perhaps else, separating user meta users, , forth)
between two, if me, i'd choose option 2. it's cleaner, in lot of circumstances, , don't have several levels and/or unknown number of levels. if both of statements true, easier maintain option 2, opposed option 1.
Comments
Post a Comment