Junior — Middle
Can you explain what the term 'synthetic key' means in the context of databases?
sobes.tech AI
Answer from AI
A synthetic key is an artificially created unique identifier for a record in a database that has no meaning outside the database itself. It is used when a natural key (for example, a combination of fields) is inconvenient or does not guarantee uniqueness.
For example, instead of using a complex composite key made up of several columns, a field with auto-increment or UUID is created. This simplifies references to records and improves performance.
A synthetic key helps to:
- Ensure the uniqueness of a record
- Simplify relationships between tables
- Avoid problems when changing data that is part of a natural key
Example: in a user table, instead of using email or full name as a key, a user_id field is created — a synthetic key.