🎁 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

Data Warehouse
A centralized repository optimized for analytical queries that integrates data from multiple operational sources.
Cursor
A database object that enables row-by-row processing of query results, useful for operations that cannot be done in bulk.
Time-Series Database
A database optimized for storing and querying timestamped data points like metrics, sensor readings, and event logs.
Foreign Key
A column that creates a link between two tables by referencing the primary key of another table.
ORM (Object-Relational Mapping)
A technique that lets you interact with a database using object-oriented code instead of writing raw SQL queries.
ACID
A set of four properties (Atomicity, Consistency, Isolation, Durability) that guarantee reliable database transactions.
View All Databases Terms →