educative.io

What is the difference between entity integrity and Key constraint?

In Educative: Interactive Courses for Software Developers

there’s mention of Entity integrity and Key constraint.
Entity integrity talks about each entity having a primary unique, non-null key. But, this is the exact same thing as having a key constraint. Wondering what exactly is the difference between these two?

Hi @kalyan

A key constraint can be literally anything. You can make a key constraint that a key can’t be blue or reference the GreenEggs table. Nothing says they have to be unique, and plenty of constrained keys aren’t.

An entity integrity constraint is just another way of saying a primary key: A unique key that must identify any individual row separately. Whether it’s autoincrement, GUID, a string, or a key over several columns, it doesn’t matter, as long as no two rows can ever have the same value.

1 Like