I have a primary key for a table with the following structure,
**Field** **Type** nid int(10)unsigned
I know the maximum limit of int(10) is 4294967295. But What happens if it exceeds the maximum? Should i have to change to bigint ?
if so what is the best practice is it to use int or big int in primary key?
Best Answer
Since you need to go to BIGINT, prepare for Disk Space Growth.
For every table that uses INT and you want to switch to BIGINT, you must forecast how much additional space to expect.
For example, for figure out how much space
mydb.mytable
will increase when you shift all INT(10) columns to BIGINT, run this queryLet's use the table
dev_oxygen.bplv_reg
Notice the table has age is int(10)
Here is the table count:
Now let's compute the number of bytes the table will have to grow:
This number is just the size increase (in bytes) for the
age
column.What about the
id
? It's not int(10) but int(11). Could you forecast for int(11), Sure, just replaceint(10)
in the query withint(11)
.What about the primary key and what if a primay key has multiple int columns defined as int(11)?
Let's pick a different table called
oxygen.history;
This table has two columns in the primary key, both columns are int(11)
Based on how much increase is forecasted for the primary key, you can now increase these