数据库表设计 [英] Database Table design
问题描述
我在选择数据库表的变量类型时遇到问题。
有人可以给我一些如何选择类型的一般指导吗?以下是我的一些问题-
I am having a problem choosing the variable types for database table. Can someone please give me some general guidelines as to how to choose the types? The following are some of the questions I have --
-
用户名应该是什么? INT似乎很小,因为设计应考虑大量用户。那么如果不是INT,还有什么呢? BIGINT? VARCHAR?我不是在想什么吗?
What should an userid be? An INT seems small as the design should take large number of users into account. So if not INT what else? BIGINT? VARCHAR? Am I not thinking straight?
何时应该选择varchar和text和tinytext,binary?
When should I choose varchar and text and tinytext, binary?
我在线搜索,没有找到任何有用的链接。有人可以指出我正确的方向吗?也许我需要读书。
I searched online and did not find any helpful links. Can someone point me in the right direction? Maybe I need to read book.
推荐答案
2013年更新:互联网现在的用户数量与已签名的用户数量大致相同32位整数。 Facebook有大约十亿用户。因此,如果您打算成为下一个Google或Facebook,并且肯定会在此时之间没有时间进行重新设计,那就选择更大的产品。否则,坚持简单。
Update for 2013: The internet now has roughly the same number of users as a signed 32-bit integer. Facebook has about a billion users. So if you're planning on being the next Google or Facebook, and you definitely won't have time to re-engineer between now and then, go with something bigger. Otherwise stick with what's easy.
截至2010年:
小?您预计会有2,147,483,648个用户吗? (据记录,这相当于世界上三分之一的人,或者比使用互联网的总人数多4亿;或者比Facebook多五倍半)。
An int seems small? Are you anticipating having 2,147,483,648 users? (For the record, that's like 1 in 3 people in the world, or 400 million more than the total number of people who use the internet; or 5 and a half times more users than Facebook).
答案:使用整数。不要想太多。如果您遇到我们的老朋友32位整数无法满足您的需求的情况,那么您可能还会有一批天才的大学毕业生和50亿美元的注资来帮助解决问题。
Answer: use an int. Don't overthink it. If you get in a situation where our old friend the 32-bit integer just isn't cutting it for you, you will probably also have a staff of genius college graduates and $5b capital infusion to help solve the problem then.
这篇关于数据库表设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!