Ravi Sir's Cyber Security Cards › Revision Cards
Constraints: NOT NULL, DEFAULT, CHECK, AUTO_INCREMENT
Constraints: NOT NULL, DEFAULT, CHECK, AUTO_INCREMENT Constraints are rules the database enforces. NOT NULL : must have a value. DEFAULT : value if none given. CHECK : value must pass a test. AUTO_INCREMENT : number goes up by 1 each row. Even if app checks fail, CHECK (amount > 0) stops negative pa

Read card text
What this card says
What it is
Constraints are rules the database enforces.
NOT NULL: must have a value. DEFAULT: value if none given. CHECK: value must pass a test. AUTO_INCREMENT: number goes up by 1 each row.
Why it matters for security
Even if app checks fail, CHECK (amount > 0) stops negative payments.
Watch out
AUTO_INCREMENT IDs are easy to guess. If /invoice.php?id=1001 has no owner check, trying 1002 shows someone else’s invoice. That is IDOR.
| Constraint | Purpose |
|---|---|
| NOT NULL | Value is required |
| DEFAULT | Value used when none is given |
| CHECK | Value must satisfy a condition (enforced in MySQL 8.0.16+… |
| AUTO_INCREMENT | Automatic increasing number, usually for the primary key |
| UNIQUE, PRIMARY KEY, FOREIGN KEY | Covered in section 11.5 |
Learn more in the lesson: 11.6 Constraints: NOT NULL, DEFAULT, CHECK, AUTO_INCREMENT