Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what if int data type in mysql reaches limit while insert records?

Tags:

mysql

Although using daily in my programming , but never realized about this question :

since the int(unsigned) data type can hold values from 0 to 4294967295, what actually happens If I declare this INT fields to be auto increment and one morning, it just reaches 4294967295? The obvious answer will be it should throw an error that cannot insert further, but data never stops comin and we have to store the records that still keep commin. What to do in this case?

Also is declaring int(20) will be large enough than this default limit?

Any suggestions?

Thanks.

like image 481
JPro Avatar asked Mar 05 '10 11:03

JPro


People also ask

How can I insert more than 1000 rows in MySQL?

To avoid a situation like this where your resources of Server or Client are blocked by unwanted queries; MySQL Workbench has limited the number of rows to be retrieved by any single query to 1000. You can easily change this limit by going to MySQL Workbench >> Edit >> Preferences >> SQL Queries tab.

What happens when the column is set to auto increment and if you reach maximum value in the table?

When the AUTO_INCREMENT column reaches the upper limit of data type then the subsequent effort to generate the sequence number fails. That is why it is advised to use a large enough integer data type for the AUTO_INCREMENT column to hold the maximum sequence value required by us.

How do I set the size of an integer in MySQL?

In MySQL, INTEGER (INT) is a numeric value without a decimal. It defines whole numbers that can be stored in a field or column. In addition, MySQL supports the display_width attribute (for example, INT(1)) and the ZEROFILL attribute, which automatically adds zeros to the value depending on the display width.


1 Answers

If you get 4 billion rows, the fact that the field will overflow is probably the least of your problems.

You can declare it to be BIGINT, which holds 8 bytes. Meaning that it will count up to 18446744073709551615.

If it overflows it will go back to 0, and keep inserting, returning an error if a row exists with that number.

like image 154
Tor Valamo Avatar answered Sep 28 '22 08:09

Tor Valamo