Antipattern: One Size Fits All
Books, articles, and programming frameworks have established a cultural convention that every database table must have a primary key column with the following characteristics:
- The primary keyâs column name is id.
- Its data type is a 32-bit or 64-bit integer.
- Unique values are generated automatically.
The presence of a column named id in every table is so common that this has become synonymous with a primary key. Programmers learning SQL get the false idea that a primary key always means a column defined in this manner.
â | âCREATEâ âTABLEâ Bugs ( |
â | id âSERIALâ âPRIMARYâ âKEYâ, |
â | description âVARCHARâ(1000), |
â | â-- . . .â |
â | ); |
Adding an
Get SQL Antipatterns, Volume 1 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.