Member-only story

Why ORM Model use the ID field

The core reason is each row in a DB should be uniquely identifiable to save and retrieve.

Thus each DB needs a table name and a unique and immutable property of the entity.

The entity properties tend to change. An example is a customer amending name, email ID, or SSN. So these properties are neither unique nor immutable.

A non-decreasing unique counter `ID` for each row is a better choice. The ID is guaranteed to be unique and immutable for an entity.

ID is also called Surrogate Primary Key. Natural Primary key can change over time.

Reference

https://enterprisecraftsmanship.com/posts/entity-identity-vs-database-primary-key/

--

--

Simplify Complexity
Simplify Complexity

Written by Simplify Complexity

Golang, Distributed Systems, File Systems, Python, C/C++, Linux

No responses yet