如何避免将用户数组存储在一个字段中?我有一个会话表,该表具有包含加入会话的用户ID的字段(joinusers_id)。我应该如何处理它们?最简单的方法是用逗号分隔它们,但我想这不是最有效的方法。附件是我当前执行的会话表的屏幕截图:
好的,我们正在谈论数据库和规范化。
http://en.wikipedia.org/wiki/Database_normalization
不,请不要使用非原子场,这很不好,如果您想加入这样的非原子场,将会遇到麻烦。
我建议您这样做:
You have users, so please create a user table containing all the things belonging to a user. The user table needs a primary key: user_mailaddress
You have sessions, create a session table ... primary key: session_id
Now create a table user_session, this table has two attributes (columns) user_mailaddress and session_id using this table you can connect the two tables together.
SELECT *
FROM user
NATURAL_JOIN user_session
NATURAL_JOIN session
The natural join will join the tables, where the attributes and the contents of the attributes are comparable.
注意:表用户和会话称为实体。表user_session称为关系。因此,这称为实体关系模型。=> http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model
要更深入地阅读它:https : //www.stat.auckland.ac.nz/~paul/ItDT/HTML/node42.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句