๐ŸŽ 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

View
A virtual table defined by a SQL query that provides a simplified or restricted view of data from one or more tables.
Redis
An open-source, in-memory data store used as a database, cache, message broker, and queue with sub-millisecond response times.
EXPLAIN ANALYZE
A PostgreSQL command that shows the execution plan of a query along with actual runtime statistics for performance tuning.
CTE (Common Table Expression)
A temporary named result set defined within a SQL statement using the WITH clause, improving query readability and enabling recursion.
Full-Text Search
A technique for searching natural language text in databases using word stemming, ranking, and relevance scoring.
Primary Key
A column or set of columns that uniquely identifies each row in a database table.
View All Databases Terms โ†’