简体   繁体   English

用户表数据库最佳实践

[英]User table database best practices

I am wondering what the best practices are for organizing user data. 我想知道组织用户数据的最佳做法是什么。

Should I store all user data per row in one table or should I be cutting it up into smaller chunks and using multiple tables related by primary key? 我应该将每行的所有用户数据存储在一个表中,还是应该将其切割成较小的块并使用与主键相关的多个表?

For example. 例如。

To start I would want to record personal info like name, occupation, location etc. Eventually it would be nice to have the option to add usage history. 首先,我想记录个人信息,如姓名,职业,位置等。最终可以选择添加使用历史记录。 As in how many and which surveys they filled out and which articles they commented on. 如他们填写了多少和哪些调查以及他们评论了哪些文章。

While typing this it makes sense to me to have a table for comments a table for username+password, a table for personal info and to keep adding tables as my needs grow... 在键入这个内容时,我有一个表用于注释用户名+密码的表,个人信息表以及随着我的需求增长而不断添加表...

Would like some confirmation though. 想要一些确认。

If there are going to be one-to-many relations then you should split it up, but for things that are one-to-one you shouldn't. 如果要有一对多的关系,那么你应该把它分开,但对于一对一的事情你不应该。 So if the user is going to have multiple addresses, phone numbers, history, friends, etc, then you would have an addresses table (or phone numbers, history, or friends tables) that is tied to the customer's id. 因此,如果用户将拥有多个地址,电话号码,历史记录,朋友等,那么您将拥有与客户ID相关联的地址表(或电话号码,历史记录或朋友表)。

For the username and password you wouldn't need a separate table. 对于用户名和密码,您不需要单独的表。

The best practices is optimize your database or you really want to organize users data first you have to go with one to many relation because you can easily track the whole users data with help of join in different table like this 最佳实践是优化您的数据库,或者您真的想要首先组织用户数据,因为您可以通过加入不同的表来轻松跟踪整个用户数据

SELECT * FROM user_A a INNER JOIN userdata_B b ON a.id=b.a_id

If users contain multiple records like name name2,occupation1,occupation2,location1,location2 etc so you have to create multiple table and populate this record into these tables because if you populate the whole users data into single table the result take so much execution time 如果用户包含多个记录,如name name2,Occ​​up1,Occup2,location1,location2等,那么你必须创建多个表并将这个记录填充到这些表中,因为如果将整个用户数据填充到单个表中,结果将花费如此多的执行时间

After this apply indexing....... 在此之后应用索引.......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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