简体   繁体   中英

How to create DB tables in this case?

I have created a table called "users" which is having

  1. userID (primary key)
  2. username
  3. password
  4. name

so now scenario is each user can have n-number of categories which mean userID=1 may have category1, category2, category3 so on and again each categories may have n-number of sub categories. So how can I design my tables? Any suggestions ?

Simple, the proposed DB Design could be like the following

 1. tbl_users(uid, uname, password, Name, ...)
 2. tbl_categories(cid, cname, parent_category_id ...) -- self join
 3. tbl_user_categories (uid, cid) -- Mapping table

Some Notes:

  • Having sensitive information like user names , passwords and names and other details in one table is not advisable.
  • It is better start learning using some good tutorials over internet to understand DB concepts
  • stackoverflow is for specific coding or other specific technical problems you struck with, not for asking DB designs.

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