background preloader

Databases / SQL

Facebook Twitter

Choosing a Primary Key: Natural or Surrogate? This article overviews strategies for assigning primary keys to a table within a relational database.

Choosing a Primary Key: Natural or Surrogate?

In particular, it focuses on the issue of when to use natural keys and when to use surrogate keys. Some people will tell you that you should always use natural keys and others will tell you that you should always use surrogate keys. These people invariably prove to be wrong, typically they're doing little more than sharing the prejudices of their "data religion" with you. Primary Keys: IDs versus GUIDs.

Long-time readers of this blog know that I have an inordinate fondness for GUIDs.

Primary Keys: IDs versus GUIDs

Each globally unique ID is like a beautiful snowflake: every one a unique item waiting to be born. Perhaps that's why I read with great interest recent accounts of people switching their database tables from traditional integer primary keys ... ID Value -- ----- 1 Apple 2 Orange 3 Pear 4 Mango .. to GUID keys. ID Value ------------------------------------ ----- C87FC84A-EE47-47EE-842C-29E969AC5131 Apple 2A734AE4-E0EF-4D77-9F84-51A8365AC5A0 Orange 70E2E8DE-500E-4630-B3CB-166131D35C21 Pear 15ED815C-921C-4011-8667-7158982951EA Mango.

MySQL

When to use database views and when not. H2. Oracle SQL.