8.15. SQL Delete

8.15.1. Rationale

8.15.2. Delete One

  • Removes data from table

  • Leaves table structure intact

  • Can be narrowed down by a WHERE

DELETE FROM astronauts
WHERE id = 1;

8.15.3. Delete Many

  • Removes data from table

  • Leaves table structure intact

  • Can be narrowed down by a WHERE

DELETE FROM astronauts
WHERE agency = 'NASA';

8.15.4. Delete Query

  • Removes data from table

  • Leaves table structure intact

  • Can be narrowed down by a WHERE

DELETE FROM astronauts
WHERE firstname = 'Mark'
AND lastname = 'Watney';

8.15.5. Truncate

  • Removes all the data

  • Leaves table structure intact

TRUNCATE TABLE astronauts;

8.15.6. Drop

  • Removes all the data

  • Removes table too

DROP TABLE astronauts;