In this assignment, you'll practice working with the task management database you created in the session. You will be inserting and updating data, writing queries, querying relationships, and finally modify the database schema to add new functionality.
Tip
If problems arise, remember you can ask on Slack for help.
After the session, you should have ended up with a working tasks.sqlite3 in your assignment repo. It should mirror the following structure:
erDiagram
USER {
int id PK
string name
string email
string phone
}
STATUS {
int id PK
string name
}
TASK {
int id PK
string title
string description
datetime created
datetime updated
date due_date
int status_id FK
}
USER_TASK {
int user_id FK
int task_id FK
}
USER ||--o{ USER_TASK : assigns
TASK ||--o{ USER_TASK : is_assigned
STATUS ||--o{ TASK : has
You will use this database to complete the following assignment tasks.
Write SQL queries to perform the following operations:
- Insert a new user with your own name and email
- Insert a new task assigned to yourself with the following attributes:
- Title: "Learn SQL"
- Description: "Practice database queries"
- Status: "In Progress"
- Due date: One week from today
- Update the title of the task you just created to "Master SQL Basics"
- Change the due date of your task to two weeks from today
- Change the status of your task to "Done"
- Delete one of the tasks in the database (choose any task)
For each operation, save your SQL query in a text file.
Write SQL queries to answer the following questions:
- List all users who don't have any tasks assigned
- Find all tasks with a status of "Done"
- Find all overdue tasks (due_date is earlier than today)
Now let's modify our database structure to add more functionality:
- Add a new column called
priorityto thetasktable with possible values: 'Low', 'Medium', 'High'. 💡 Remember to provide default values. - Update some existing tasks to have different priority values
- Create a new table called
categorywith columns:- id (PRIMARY KEY)
- name (e.g., "Work", "Personal", "Study")
- color (e.g., "red", "blue", "green")
- Create a linking table called
task_categoryto establish a many-to-many relationship between tasks and categories:- task_id (FOREIGN KEY to task.id)
- category_id (FOREIGN KEY to category.id)
- Insert at least 3 categories
- Assign categories to at least 5 different tasks
Now that you've enhanced the database, write queries to:
- Find all tasks in a specific category (e.g., "Work")
- List tasks ordered by priority (High to Low) and by due date (earliest first)
- Find which category has the most tasks
- Get all high priority tasks that are either "In Progress" or "To Do"
- Find users who have tasks in more than one category
Submit your assignment as a single .sql file containing all your queries, clearly labeled with comments indicating which part and question each query addresses.
Example:
-- Part 1, Question 1: Insert a new user
INSERT INTO user (name, email, phone) VALUES ('My Name', 'my_email@example.com', '123-456-7890');
-- Part 1, Question 2: Insert a new task
INSERT INTO task (title, description, created, updated, due_date, status_id)
VALUES ('Learn SQL', 'Practice database queries', datetime('now'), datetime('now'), date('now', '+7 days'), 2);Start progress on the Events Startup Project. Check the Weekly Plan for specific tasks to complete this week.