Database Constraints
Types of Constraints:
Primary Key – Ensures that a column (or set of columns) has unique values and cannot be NULL.
Foreign Key – Enforces referential integrity by linking a column to another table’s primary key.
Unique Constraint – Guarantees that all values in a column are distinct and
Not Null – Prevents NULL values in a column.
Check Constraint – Defines conditions that data must meet (e.g., age >= 18).
Default Constraint – Provides a default value when none is specified.
Why Constraints Are Important:
Data Integrity – Constraints prevent incorrect or inconsistent data entry.
Referential Integrity – Foreign keys ensure relationships between tables remain valid.
Error Prevention – Helps detect and avoid mistakes before they affect the database.
Performance Optimization – Constraints allow databases to optimize queries more efficiently.
