🎁 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

Migration
A version-controlled change to a database schema that can be applied and reversed systematically.
ACID
A set of four properties (Atomicity, Consistency, Isolation, Durability) that guarantee reliable database transactions.
MVCC (Multi-Version Concurrency Control)
A technique where the database maintains multiple versions of data to allow concurrent reads and writes without locking.
Elastic Search
A distributed search and analytics engine built on Apache Lucene, optimized for full-text search and log analysis.
Data Warehouse
A centralized repository optimized for analytical queries that integrates data from multiple operational sources.
EXPLAIN Plan
A database command that shows how the query planner will execute a SQL query, revealing join methods, scan types, and estimated costs.
View All Databases Terms →