0
0
SQLquery~30 mins

NOT NULL constraint in SQL - Mini Project: Build & Apply

Choose your learning style9 modes available
Using NOT NULL Constraint in SQL
📖 Scenario: You are creating a simple database table to store information about employees in a company. Each employee must have a unique ID and a name. The name cannot be empty because it is important to identify each employee.
🎯 Goal: Create a table called employees with two columns: id and name. The id column should be an integer and the primary key. The name column should be text and must not allow NULL values.
📋 What You'll Learn
Create a table named employees
Add an id column of type INTEGER as the primary key
Add a name column of type TEXT with a NOT NULL constraint
💡 Why This Matters
🌍 Real World
Ensuring important data fields like employee names are always filled in a company database.
💼 Career
Database developers and administrators use NOT NULL constraints to maintain data integrity and prevent missing critical information.
Progress0 / 4 steps
1
Create the employees table with id column
Write a SQL statement to create a table called employees with one column id of type INTEGER that is the primary key.
SQL
Need a hint?

Use CREATE TABLE employees and define id INTEGER PRIMARY KEY.

2
Add the name column with NOT NULL constraint
Modify the employees table creation statement to add a name column of type TEXT that has a NOT NULL constraint.
SQL
Need a hint?

Add name TEXT NOT NULL as a column definition.

3
Insert a valid employee record
Write a SQL statement to insert a new employee with id 1 and name 'Alice' into the employees table.
SQL
Need a hint?

Use INSERT INTO employees (id, name) VALUES (1, 'Alice').

4
Try inserting a record with NULL name (should fail)
Write a SQL statement to insert a new employee with id 2 and name as NULL into the employees table. This should fail because of the NOT NULL constraint.
SQL
Need a hint?

Use INSERT INTO employees (id, name) VALUES (2, NULL) to see the NOT NULL constraint in action.