What are database constraints and what types exist?

Answer

Database constraints enforce rules on the data stored in tables, ensuring integrity at the database level regardless of application code. Types: NOT NULL — column must have a value; UNIQUE — all values in a column (or group) must be distinct; PRIMARY KEY — uniquely identifies rows (NOT NULL + UNIQUE); FOREIGN KEY — referential integrity between tables; CHECK — custom condition must be true for all row values; DEFAULT — specifies a value when none is provided (technically not an integrity constraint). Constraints can be defined at column level (inline) or table level. Named constraints are easier to identify in error messages.