如何标准化或设计我的 MySQL 数据库
我想知道哪一种结构适合同时存储大约50条数据到MySQL中?
第一
data_id user_id data_key data_content
---------------------------------------------------
1 2 data_key1 content 1
2 2 data_key2 content 2
3 2 data_key3 content 3
.. .. .. ..
.. .. .. ..
50 2 data_key50 content 50
秒
data_id user_id data_key1 data_key2 data_key3 .. .. data_key50
-------------------------------------------------------------------
1 2 content 1 content 2 content 3 .. .. content 50
还是有其他解决方案? user_id
将拥有超过 5000 个用户。
I want to know which one structure is good to store about 50 data in same time into MySQL?
First
data_id user_id data_key data_content
---------------------------------------------------
1 2 data_key1 content 1
2 2 data_key2 content 2
3 2 data_key3 content 3
.. .. .. ..
.. .. .. ..
50 2 data_key50 content 50
Seconds
data_id user_id data_key1 data_key2 data_key3 .. .. data_key50
-------------------------------------------------------------------
1 2 content 1 content 2 content 3 .. .. content 50
Or have other solution? user_id
will have more than 5000 users.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您事先知道数据密钥吗?它们可能会改变吗?如果它们符合“名字、姓氏、头发颜色、眼睛颜色、生日……”,那么第二个模型是可行的,因为您经常希望同时为用户检索所有这些信息。
第一个模型就像拥有一个持久哈希表,因此您必须将所有值存储为字符串,并且您的应用程序必须知道要查询哪些键。但是,如果键是用户定义的,则这可能是有意义的。
Do you know the data keys before hand and are they likely to change? If they're along the lines of "first_name, last_name, hair_color, eye_color, birthday, ..." then the second model would be feasible since you'll often want to retrieve all of these for a user at the same time.
The first model is like having a persistent hashtable, so you'd have to store all the values as strings, and your app will have to know which keys to query for. This can make sense if the keys are user defined, however.
绝对是第一!如果需要 50 多个不同的“数据密钥”怎么办?第一种解决方案更加灵活且不受污染。
Definitely the first one! What if the need arises to have more than 50 different "data keys". The first solution is way more flexible and unpolluted.
我不认为第二种解决方案是好的。
如果我没有假设错误的话,并不是所有的 tue 用户都是 2,但是你有不同的数字,你应该做的是规范化该表,将其划分为。
一个有:
表主:
id , data_id, user_id
表键
main_id, data_key
表数据:
main_id,data_content
其中表中的 key 和 data main_id 都引用了表 main 中的 id,这是连接它们的方式
I do not think the second solution is a goeod one.
If I do not suppose wrong not all tue users are 2, but you have different numbers what you should do is normalize that table, divide it in to.
One that has:
Table main:
id , data_id, user_id
Table key
main_id, data_key
Table data:
main_id,data_content
where in both tables key and data main_id reffer to the id in the table main, which is the way to join them