Interview Question

What are constraints in SQL?

Constraints make the database enforce data rules.

💡 Concept ✅ Quick Revision 🗃️ SQL

Answer

Constraints declare rules that table data must satisfy. • Common constraints include NOT NULL, CHECK, UNIQUE, PRIMARY KEY, and FOREIGN KEY. • They centralize integrity rules inside the database. • Constraint enforcement can reject invalid INSERT or UPDATE statements.

💡 SQL Example

CREATE TABLE products (product_id integer PRIMARY KEY, price numeric CHECK (price >= 0));

Result

CREATE TABLE

⚡ Quick Revision

Constraints make the database enforce data rules.