constraint
A rule the database enforces on stored data, such as a column that must be unique or not null.
In more detail
Constraints protect data even from programs that skip application checks. Common examples are primary keys, unique columns, foreign keys and not-null columns.
Example
In this course: A test that inserts a row, then a second row that breaks the rule, and expects the database to reject it proves the constraint really exists. Fakes and in-memory stand-ins usually do not enforce constraints, which is why this belongs in a real database test.Related terms
- primary key — The column, or columns, whose value uniquely identifies each row of a table and can never be NULL.
- relational database — A database that stores data in tables and links rows in one table to rows in another through shared key values.
- foreign key — A column holding another table's primary key value, which the database guarantees points at a row that exists.
- unique constraint — A constraint that no two rows may have the same value in a column or combination of columns.
- NOT NULL — A constraint that a column must always hold a value, so NULL is rejected.
- CHECK — A constraint that each row must satisfy a condition, such as quantity > 0 or a status from a fixed list.
- database engine — The database software itself, such as PostgreSQL, MySQL or SQLite, which decides the features, SQL dialect and extensions available.
Taught in
- Persistence With JPA And Hibernate — Modern Java: Virtual Threads & High-Throughput Services
- Tying It All Together — Modern Java: Virtual Threads & High-Throughput Services
- Why Tables And Relations Beat Files — PostgreSQL, Indexing & Relational Data Modeling
- Keys, Constraints And Referential Integrity — PostgreSQL, Indexing & Relational Data Modeling
- Inserting Data Safely — PostgreSQL, Indexing & Relational Data Modeling
- Transactions And ACID Properties — PostgreSQL, Indexing & Relational Data Modeling
- Testing With Real Databases — Automated Testing, TDD & Quality Engineering