简体   繁体   English

数据库交叉值存储的最佳实践

[英]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.

相关问题 PHP - 在数据库中存储页面视图的最佳实践 - PHP - Best practice for storing page view in database 最佳实践数据库事务并将文件存储到PHP中的文件系统中 - Best practice database transactions and storing files onto filesystem in PHP 在数据库表中存储大量数据的最佳实践 - Best practice for storing very large amount of data in database table 与Zend合作时在数据库中存储加密电子邮件的最佳实践 - Best practice for storing emails encrypted in a database when working with Zend 在服务器上存储图像的最佳实践 - Best practice with storing images on server 存储网站设置的最佳做法? - Best practice for storing settings for a website? mysql数据库存储最佳实践,用于存储数据(少量或少量大量) - mysql database storing best practice for storing data, lots of small amounts or small amounts of large 在MySQL数据库中存储原始php,javascript,html或类似内容的最佳实践方法是什么? - What's the best practice method for storing raw php, javascript, html or similar in a mysql database? 在PHP中存储全局数据的最佳实践? - Best practice for storing global data in PHP? 在 mysql DB 中存储 HTML 的最佳实践 - Best practice for storing HTML in mysql DB
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM