MySQL + SQL · Lesson 39

NOT NULL, UNIQUE, CHECK and DEFAULT

Column-Level Constraints

These constraints control what values a column will accept, keeping data clean.

Each Constraint

CREATE TABLE students (
  roll_no INT PRIMARY KEY,
  name VARCHAR(50) NOT NULL,          -- must have a value
  email VARCHAR(60) UNIQUE,           -- no duplicates
  marks INT CHECK (marks BETWEEN 0 AND 100),  -- valid range
  status VARCHAR(10) DEFAULT 'active' -- auto value
);

Quick Meaning

ConstraintRule
NOT NULLcannot be empty
UNIQUEno repeated values
CHECKvalue must pass a condition
DEFAULTused when no value is given

Summary

  • NOT NULL = required; UNIQUE = no duplicates.
  • CHECK = condition must hold; DEFAULT = auto value.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n

💻 Live Code Editor

Is page ki language (MYSQL) mein code likhein aur turant chalाएं — yahीं, bina kuch install kiye.
Powered by OneCompiler. Agar editor na khule to yahान naye tab mein kholein.

💻 Live Code Editor

Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें. Agar load na ho to naye tab mein kholें.