Teaching Your Database to Say “YES” and “NO” with DEFAULT and CHECK Constraints
Imagine your database is a school If there are no rules, students can: That would be chaosSo we use constraints to keep data clean, safe, and sensible. Today, we learn two important rules: We’ll learn this using MySQL. What Is a Constraint? A constraint is a rule applied to a column to control what data can go inside it. Think of it as: Traffic rules for your database roads DEFAULT Constraint – The Helpful Friend What Is DEFAULT? The DEFAULT constraint gives a column a predefined valueOnly when you don’t provide one Example If you forget your school uniform, the…
