Practice and reinforce the concepts from Lesson 2
You're managing a simple task list and need to learn the four basic SQL operations: CREATE, READ, UPDATE, DELETE (CRUD).
Scenario: Build a personal task management system using SQL.
-- Create a simple tasks table
CREATE TABLE tasks (
id INT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(100),
description TEXT,
completed BOOLEAN DEFAULT false,
created_date DATE
);
-- Add sample tasks
INSERT INTO tasks (title, description, created_date) VALUES
('Learn SQL', 'Complete database fundamentals course', '2024-01-15'),
('Build project', 'Create a web application', '2024-01-16'),
('Practice queries', 'Write 10 different SQL queries', '2024-01-17'),
('Study database design', 'Learn about normalization', '2024-01-18'),
('Review concepts', 'Go through all course materials', '2024-01-19');
CRUD stands for Create, Read, Update, Delete - the four basic database operations.
The Four Essential Queries:
-- Add a new task
INSERT INTO tasks (title, description, created_date)
VALUES ('Review database concepts', 'Study for upcoming test', '2024-01-20');
-- View all tasks
SELECT * FROM tasks;
-- View specific columns
SELECT title, completed FROM tasks;
-- Filter with WHERE
SELECT title FROM tasks WHERE completed = false;
-- Mark a task as completed
UPDATE tasks
SET completed = true
WHERE title = 'Learn SQL';
-- Update multiple fields
UPDATE tasks
SET completed = true, description = 'Successfully completed!'
WHERE id = 1;
-- Remove a specific task
DELETE FROM tasks WHERE id = 5;
-- Remove completed tasks
DELETE FROM tasks WHERE completed = true;
Test each operation:
SELECT * FROM tasks
SELECT * FROM tasks WHERE id = 1
Expected behavior:
For advanced SQL concepts including complex queries, performance optimization, and database design principles, see:
/* Reference link removed - file doesn't exist **[SQL Advanced Theory →](./Reference/Database-Theory/SQL-Advanced.mdx)** */Topics covered there:
Complete this activity and submit your work through the Activity Submission Form