Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when DB engine runs out of numbers to use for primary keys?

Since DBs do not reuse numbers of deleted records it is possible to run out of numbers, especially if you pick not really a big integer type for this column.
What would happen and how to prevent it if it's bad?

// SQL Server, MySQL //

like image 843
z-boss Avatar asked Oct 31 '08 14:10

z-boss


People also ask

Do primary keys need to be numbers?

No, the primary key does not have to be an integer; it's just very common that it is. As an example, we have User ID's here that can have leading zeroes and so must be stored in a varchar field. That field is used as a primary key in our Employee table.

What is a requirement regarding primary keys in a SQL database?

Primary keys must contain unique values. A primary key column cannot have NULL values. A table can have only one primary key, which may consist of single or multiple fields. When multiple fields are used as a primary key, they are called a composite key.

What happens if there is no primary key in SQL?

Every table should have some column (or set of columns) that uniquely identifies one and only one row. It makes it much easier to maintain the data. It's true, without a primary key (or some unique key), you don't have an insertion anomaly if you go to insert the same data multiple times.

Can we have 0 in primary key?

Primary Key Can be Zero, but if you set Identity on the column it normally will start at 1 rather than Zero. Primary Key will have Identity Column ..


1 Answers

You end up with a 3+ Hour Downtime, like Slashdot did on their Comments-Function.

like image 179
Michael Stum Avatar answered Oct 07 '22 15:10

Michael Stum