SQL Fundamentals

Lesson 5 of 6

Modifying Data: INSERT, UPDATE, DELETE

So far every example has only read data. These three statements change it.

INSERT INTO students (name, xp)
VALUES ('Grace', 0);

UPDATE students
SET xp = xp + 25
WHERE name = 'Grace';

DELETE FROM students
WHERE xp = 0 AND name = 'Inactive User';
  • INSERT INTO table (columns) VALUES (...) adds a new row.
  • UPDATE table SET column = value WHERE ... modifies existing rows that match the condition.
  • DELETE FROM table WHERE ... removes matching rows.

WARNING

UPDATE and DELETE without a WHERE clause apply to every row in the table. Forgetting the WHERE is one of the most common, and most costly, mistakes in SQL, always double-check it before running either statement.

📝 Modifying Data Quiz

Passing score: 70%
  1. 1.Which statement adds a brand-new row to a table?

  2. 2.Running UPDATE students SET xp = 0 without a ____ clause would reset every row.

  3. 3.Forgetting the WHERE clause on an UPDATE or DELETE is a common and costly mistake.