Insert, update, delete

INPUT · Slides

Insert, update and delete: putting it together

01 / 03

Three statements, all present

These are the three statements that change things. Lay the shapes out side by side.

  • add … INSERT INTO table (columns...) VALUES (values...);
  • fix … UPDATE table SET column = value WHERE condition;
  • delete … DELETE FROM table WHERE condition;

Four, counting the SELECT that reads. That is enough for an app to work its data.

02 / 03

Decide what you are aiming at first

UPDATE and DELETE have their targets decided by the WHERE. The procedure is always the same.

  • SELECT with the same WHERE and see how many rows there are
  • if that is what you meant, make the change
  • SELECT once more and look at the result

Just do not forget that leaving the WHERE out makes it bite on every row.

03 / 03

You choose how to check, too

The checking SELECT can use every way of reading you have learned. Sort, narrow, count, gather by group.

Below gathers the places together and then looks at the total per place. The heading stays as the expression you wrote, SUM(stock).

This lesson is ten practice questions only. Each comes with its own checking query, so write in a way that changes what it returns.

UPDATE tools SET place = 'shelf'  WHERE place = 'locker';SELECT place, SUM(stock) FROM tools  GROUP BY place ORDER BY place;

Result

basket | 8
shelf | 39
store | 15