🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

Databases Beginner

What is Database Constraint?

Rules enforced by the database to maintain data integrity, including NOT NULL, UNIQUE, CHECK, PRIMARY KEY, and FOREIGN KEY.

Constraints are declarative rules that the database enforces automatically. NOT NULL prevents missing values. UNIQUE ensures no duplicate values in a column. CHECK validates that values meet a condition (e.g., price > 0). PRIMARY KEY combines NOT NULL and UNIQUE to identify rows. FOREIGN KEY enforces referential integrity between tables. EXCLUDE constraints (PostgreSQL) prevent overlapping ranges. Constraints catch data errors at the database level regardless of which application inserts data, providing a critical safety net that application-level validation alone cannot guarantee.

Related Terms

Cursor
A database object that enables row-by-row processing of query results, useful for operations that cannot be done in bulk.
Window Function
An SQL function that performs calculations across a set of rows related to the current row without collapsing the result set.
CTE (Common Table Expression)
A temporary named result set defined within a SQL statement using the WITH clause, improving query readability and enabling recursion.
Schema
The structure definition of a database including tables, columns, data types, relationships, indexes, and constraints.
B-Tree Index
The default index type in most databases that organizes data in a balanced tree structure for efficient searching, sorting, and range queries.
Database Connection Pooling
A technique that maintains a cache of database connections for reuse, reducing the overhead of creating new connections.
View All Databases Terms →