问题描述
我在选择数据库表的变量类型时遇到问题。
有人可以给我一些一般的指导,如何选择类型?以下是我有的一些问题 -
-
用户ID应该是什么? INT似乎很小,因为设计应该考虑大量的用户。所以如果不是INT还有什么? BIGINT? VARCHAR?
-
我应该什么时候选择varchar和text和tinytext,二进制?
我在线搜索,没有找到任何有用的链接。有人能指点我的方向吗?可能是我需要读书。
- Pav
2013年更新:互联网现在拥有与签名的32位整数大致相同的用户数。 Facebook有大约10亿用户。所以,如果你打算成为下一个Google或Facebook,并且你肯定不会有时间重新设计,现在和现在,再去更大的东西。
$ b
自2010年起:
小?您预计有2,147,483,648个用户? (对于记录,这就像世界上3个人中的1个,或者比使用互联网的总人数多4亿;或者比Facebook的用户多1.5倍)。答案:使用int。不要过分考虑。如果你遇到一个情况,我们的老朋友的32位整数只是不是为你切削,你可能也有一个天才大学毕业生的工作人员和$ 5b资本注入,以帮助解决这个问题。
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 --
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?
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? May be I need to read book.
- Pav
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.
As of 2010:
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).
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.
这篇关于表设计问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!