filmov
tv
SQL primary key, surrogate key, composite keys, foreign keys...
Показать описание
Then the idea of a little demo to show common misconceptions:
- you don't need a primary key
- you may have multiple keys and choose one arbitrarily to be the primary one (some RDBMS engines will sue it for table storage layout)
- generated key is not necessarily a surrogate key
- composite key can be a concatenation of surrogate keys
...
A key, primary or not, has 3 goals:
- guarantees one row (👉 less code)
- gives fast access path (👉 better performance)
- be referenced by a foreign key
The demo is on 🚀 YugabyteDB database, which is 🐘 PostgreSQL compatible