Most likely primary keys in databases are numbers. But what happens, when an administrator uses the wrong numeric data type? In the worst case, databases can’t write down entries anymore.
For example, if an administrator wants to write customer information into the databases and wants to use the customerID itself as the primary key, then the numeric data type “TINYINT” would cause that only 255 entries can be written. But on the other hand the “BIGINT” numeric data type, could be too large for smaller databases.
So when you are setting up a database, you should think about how many entries will be written the next months/years and think about which datatype is the right one for your setup. Also you should think about if you should use the data types unsigned or not. This value will change the range of the datatypes.
||-263||+263 – 1||0||264 – 1|
If an administrator wants to store 60000 customer information in the database, he should use at least a “SMALLINT”. Should he use the unsigned version or not? Lets have a look.
With the signed data type he has a range from -32.768 up to +32.767, but no customerID (primary key as mentioned above) has a negative number, so a “unsigned SMALLINT” would be necessary.
The case, that you thought about the questions above but your data type got out of range, could happen. There is a way to change the datatype and to increase the range in a simple way.
*ALTER TABLE tablename MODIFY column MEDIUMINT UNSIGNED;*
But remember: The larger your database is, the longer will it take to do such changes!