2 ms·
Why does anything need to be a primary key anywhere in order to enforce some constraint? At least from ORMs I know I can set for example any group of attributes
by zelphirkalt 2y ago
Why does anything need to be a primary key anywhere in order to enforce some constraint?
At least from ORMs I know I can set for example any group of attributes unique. Other constraints can be implemented in some general method that is called when persisting in the actual database.
Even if no ORM, you can write a wrapper around your persisting procedure.
- sgarland 2y agoIt doesn’t, you’re right. However, indexes aren’t free, so if your data is such that a natural PK (composite or otherwise) makes sense, you’ll save RAM. Also, for clustering RDBMS like MySQL, data is stored around the PK, so you can get some locality boosts depending on query patterns.
- a57721 2y ago> At least from ORMs I know I can set for example any group of attributes unique Just in case, ORMs send DDL statements with uniqueness constraints to the DBMS, they don't do any magic here.