Using NOT NULL and DEFAULT Constraints in MySQL
📖 Scenario: You are creating a simple database table to store information about employees in a company. Each employee must have a name and a department. The department should default to 'General' if not specified.
🎯 Goal: Create a MySQL table called employees with columns that use NOT NULL and DEFAULT constraints to ensure data integrity.
📋 What You'll Learn
Create a table named
employeesAdd a column
id as an integer primary keyAdd a column
name as a VARCHAR(50) that cannot be NULLAdd a column
department as a VARCHAR(50) that cannot be NULL and defaults to 'General'💡 Why This Matters
🌍 Real World
Ensuring data integrity in employee databases by preventing missing important information and providing default values.
💼 Career
Database administrators and developers often use <code>NOT NULL</code> and <code>DEFAULT</code> constraints to maintain clean and reliable data.
Progress0 / 4 steps