๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout 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

Trigger
A database object that automatically executes a specified function when certain events (INSERT, UPDATE, DELETE) occur on a table.
Soft Delete
A pattern where records are marked as deleted with a flag or timestamp rather than being physically removed from the database.
Primary Key
A column or set of columns that uniquely identifies each row in a database table.
Database Sharding
A horizontal scaling strategy that distributes data across multiple database servers based on a partition key.
Connection Pool
A cache of database connections that can be reused, avoiding the overhead of creating new connections for each request.
Replication
The process of copying and maintaining database data across multiple servers for redundancy, failover, and read scaling.
View All Databases Terms โ†’