Surrogate key
A surrogate key is an artificially assigned, domain-independent identifier used to uniquely identify a database record independently of its business attributes.
Grokking Relational Database Design
A surrogate key is an artificially created key value used to uniquely identify a row independently of the row's natural attributes.
- How it is used
- Identifies rows when no stable natural attribute can serve as a primary key.
- How deep it goes
- Explains auto-incrementing numeric IDs and their duplication limitation, then applies unique constraints to customer and dealer design.
- Examples
- Uses review_id for reviews and customer_id for customers whose email addresses and phone numbers can change.
- What you can do after
- Apply it by choosing an auto-incrementing ID for row identity and adding unique constraints where duplicate natural data is unacceptable.
Read how Grokking Relational Database Design explains surrogate key →
Java Persistence with Spring Data and Hibernate epub
A surrogate key is an application-meaningless primary key whose purpose is to identify stored data internally.
- How it is used
- Uses internal identifiers to decouple database identity from mutable or absent business keys.
- How deep it goes
- Explains rationale, foreign-key consequences, schema tradeoffs, and generation configuration, but defers Java-domain representation and generation strategies.
- Examples
- Uses USERS and BILLINGDETAILS tables with generated ID columns and a USER_ID foreign key.
- What you can do after
- Evaluate primary-key choices and configure generated identifiers when designing persistent tables and ORM mappings.
Read how Java Persistence with Spring Data and Hibernate epub explains surrogate key →
DuckDB in Action
A surrogate primary key is an artificially assigned identifier used as the primary key of a table instead of being derived from business data.
- How it is used
- Uses artificial identifiers to address rows when business attributes are not reliably unique.
- How deep it goes
- Defines surrogate keys and demonstrates sequence-backed creation, while contrasting them with externally generated and composite keys.
- Examples
- Demonstrates an externally generated system ID and a sequence-backed price ID in an energy-consumption schema.
- What you can do after
- Build it from scratch with SQL sequences, primary-key declarations, and separate business-uniqueness constraints.
Also covered in
What to know first
- universally unique identifierA universally unique identifier (UUID) is a standardized 128-bit identifier designed to be practically unique across independently generated values and systems.
Related concepts
- composite keyalternative to · A composite key is a key formed from multiple attributes or values whose combination identifies or uniquely distinguishes a record or item.
- primary keykind of · A primary key is a field or combination of fields whose values uniquely identify each row or item in a data store.
- natural keyalternative to · A natural key is an identifier formed from meaningful domain attributes whose values uniquely identify an entity or record.
- business keyalternative to · A business key is one or more domain-meaningful properties whose values identify a business entity or distinguish it for matching and uniqueness.
- @GeneratedValueconfigured by · @GeneratedValue is a Jakarta Persistence annotation that configures automatic generation of an entity identifier according to a specified strategy.
Questions about surrogate key
What is surrogate key?
A surrogate key is an artificially assigned, domain-independent identifier used to uniquely identify a database record independently of its business attributes.
Which Manning books explain surrogate key?
Grokking Relational Database Design, Java Persistence with Spring Data and Hibernate epub and DuckDB in Action.
What should I know before learning surrogate key?
Manning books that teach surrogate key usually introduce universally unique identifier first.
What is the difference between surrogate key and composite key?
A surrogate key is an artificially assigned, domain-independent identifier used to uniquely identify a database record independently of its business attributes. A composite key is a key formed from multiple attributes or values whose combination identifies or uniquely distinguishes a record or item.
What is surrogate key a kind of?
Surrogate key is a kind of primary key. A primary key is a field or combination of fields whose values uniquely identify each row or item in a data store.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


