[英]Best practice for database cross-value storing
I have one table in my db that looks like this: 我的数据库中有一张表,如下所示:
| userid | username | dateloggedin | etc
| 1 | Joebloggs | 27-03-16 | etc
| 2 | Nathanbloggs| 27-03-16 | etc
and a logging table that looks like this: 日志表如下所示:
| eventtype | userid | eventdate | etc
| loggedin | 1 | 27-03-16 | etc
| loggedout | 1 | 27-03-16 | etc
When I display the entries from the eventlog I want to also display the username, not just the userid. 当我显示事件日志中的条目时,我还想显示用户名,而不仅仅是用户ID。
What's the best practice here, should I store the username in both the eventlog table and the users table so I can access all data in a single query? 这里的最佳做法是什么,我应该将用户名同时存储在eventlog表和users表中,以便可以在单个查询中访问所有数据吗? Or should I use the userid to cross reference the other table and get the username from there, only storing it once?
还是我应该使用userid交叉引用另一个表并从那里获取用户名,只存储一次?
Given that I am planning for volumes I'm not sure which route is best - more processing time from switching between queries and arrays, or more storage space used by duplicating data. 鉴于我正在计划卷,因此我不确定哪条路由是最佳的-在查询和数组之间切换会花费更多的处理时间,或者通过复制数据会花费更多的存储空间。
http://www.tutorialspoint.com/sql/sql-using-joins.htm http://www.tutorialspoint.com/sql/sql-using-joins.htm
This link explains the sql JOINS syntax quite well, thanks! 此链接很好地解释了SQL JOINS语法,谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.