Lesson 4: SQL Constraints (Rules for Your Data).
Welcome to Lesson 4. In the last lesson, we learned about Data Types (Text, Numbers, Dates). But simply knowing the type isn't enough. Imagine a "Sign Up" form on a website. What happens if: A user tries to sign up without a password ? Two users try to use the same email address ? The database must stop this! We use Constraints to enforce these rules. 1. What are SQL Constraints? Constraints are rules we apply to columns to ensure the data is accurate and reliable. If you try to insert data that breaks a rule, the database will say "Error" and reject it. 2. The 6 Most Important Constraints Here are the rules you will use in almost every table: Constraint The Rule Real Life Example NOT NULL The column cannot be empty. A user must have a Password. UNIQUE No duplicate values allowed. Two users cannot have the same Email . DEFAULT ...