简体   繁体   中英

Relating my normalized tables together

I have a range of tables that I have normalized for a user profile section. The tables are as follows;

users --> userProfileSettings --> userPersonalInfo --> userContactInfo --> userAddresses --> userBusinessInfo --> userBusinessTags --> userBusinessLogo

The users table contains the username and password, with the profile settings containing information as to whether the account is active/inactive and the date they became a member. The way I have this in my head - is a user can have only one entry in each table - and must have an entry in each table (apart from userBusinessLogo) in order to be a member, the only table which would allow multiple rows to be indentifed to a user would be the userBusiness tags.

What would be the best way to achieve this, as one to many relationships would allow multiple rows of the same user? I have been searching around for a similar kind of setup but I cannot seem to find any examples.

You have probably over-normalized your schema. In general, if you have a strict one-to-one relationship between tables, you should seriously consider merging them into a single table. If a user can truly only have one set of personal info, one set of contact info, one address, and one set of business info, then put these all together into one table so you don't have to worry about unintentionally violating these constraints in your database.

Experience has taught me that contact info and addresses usually end up as many-to-one relationships with person/user records, so you might reconsider whether they (or the other tables) are truly one-to-one for the purposes of your app.

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