1

Is it ok to use INT as the datatype for the index in MySQL. I'm not sure if this is the best way to go as I fully expect this table to get a lot of entries that will eventually 'overflow' the INT

I doubt something like Facebook uses INT for their index on something such as the wallpost table or something else that would be high traffic / get lots of entries.

Any thoughts?

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
john
  • 23
  • 1
  • 3

3 Answers3

2

use INT( 11 ) UNSIGNED ZEROFILL NOT NULL

xkeshav
  • 53,360
  • 44
  • 177
  • 245
1

An INT can go up to over 2 billion (twice that many if unsigned). If you expect your table to have more rows than that, you can use a BIGINT (which unsigned goes up to 18,446,744,073,709,551,615—probably more than even Facebook needs).

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
1

Generally speaking, you have two choices:

A 'natural key' that reflects the reality of the data you are working with. For example, a telephone number might be a valid primary key for a calling list, but it would not be appropriate at all for, say, a list of health care beneficiaries because many people might share the same phone number in a home. Note that a natural key might be made up of more than one field. For example, the combination of Make, Model, and Year might be a key for a list of automobile models.

A 'surrogate key' on the other hand, is just an arbitrary value that you assign to a row. If you go that route, I'd recommend using a GUID (UUID in MySql). The best way that I know to represent those in MySQL is with a char(36) column. GUIDs are effectively unique forever and can be used infinitely.

If you insist on using a plain old number, then INT is probably fine, or you can use BIGINT to be really sure.

BIGINT UNSIGNED ZEROFILL
Community
  • 1
  • 1
JosephStyons
  • 57,317
  • 63
  • 160
  • 234