Learn Without Walls
← Back to SQL Labs
← Previous Lab Lab 9 of 10 — INSERT, UPDATE, DELETE & CREATE Next Lab →

Lab 09 — INSERT, UPDATE, DELETE & CREATE

Not just reading data — writing it. Create tables, insert rows, update records, and safely delete data. The database resets on every page reload so experiment freely!

Loading SQL engine...
STARTING TABLE: students (starts EMPTY — you will populate it!)TABLE: students id INTEGER PRIMARY KEY AUTOINCREMENT name TEXT NOT NULL major TEXT gpa REAL year INTEGER The table is empty. Your INSERT statements will fill it. Page reload resets everything -- experiment without fear!

Concept Recap: DDL & DML

DDL (Data Definition Language) — defines structure:

DML (Data Manipulation Language) — modifies data:

Worked Example (read-only)

Create a table, insert rows, update a price, and verify the result.

CREATE TABLE IF NOT EXISTS products (
    id    INTEGER PRIMARY KEY AUTOINCREMENT,
    name  TEXT NOT NULL,
    price REAL,
    stock INTEGER DEFAULT 0
);
INSERT INTO products (name, price, stock) VALUES ('Laptop', 999.99, 50);
INSERT INTO products (name, price, stock) VALUES ('Mouse', 29.99, 200);
UPDATE products SET price = 899.99 WHERE name = 'Laptop';
SELECT * FROM products;
Guided

Exercise 1 — Your First INSERT

Insert 3 students into the students table. Fill in the VALUES for students 2 and 3, then run a SELECT to verify they were added.

Hint: Column order is (name, major, gpa, year). The id is AUTOINCREMENT so omit it.
Independent

Exercise 2 — INSERT, UPDATE, and DELETE a Full Workflow

Build up the table step by step. Run each block individually to see changes. Do the following in sequence:

  1. Insert 5 students (mix of majors, GPAs 2.8–3.9, years 1–4).
  2. Update Alice's GPA to 3.95 (use WHERE name = 'Alice Chen').
  3. Update all 'English' major students to year 2.
  4. Delete all students with GPA below 3.0.
  5. Run SELECT * to verify final state.
Remember: Always use WHERE with UPDATE and DELETE!
Challenge

Exercise 3 — Build Two Related Tables and JOIN Them

Create a courses table and an enrollments table. Insert data, then write a JOIN query to show which students are enrolled in which courses.

Hint: courses(id, course_name, credits), enrollments(student_id, course_id, grade). Use AUTOINCREMENT for the id columns.
Mini Project

Mini Project — Full Student Registration System

Build a complete student registration system from scratch in a single editor. The database starts fresh every page reload, so you can run the whole block at once.

  1. INSERT a full class of 6 students.
  2. UPDATE 2 students — one GPA correction, one major change.
  3. DELETE 1 student who withdrew.
  4. CREATE a grades table: grades(id, student_id, subject, score, grade_letter).
  5. INSERT grades for 4 remaining students across at least 2 subjects each.
  6. Final SELECT: join students with grades to show complete academic status.

Lab 09 Complete!

You can now create tables with constraints, insert rows, update specific records, and safely delete data. You also know why WHERE is non-negotiable with UPDATE and DELETE.

One lab to go — the capstone. No fill-in-the-blanks. Real analyst questions.

Continue to Lab 10 — Capstone →