Delete your data

Applying SQL to Real-World Problems

Dmitriy (Dima) Gorenshteyn

Lead Data Scientist, Memorial Sloan Kettering Cancer Center

DROP, TRUNCATE, DELETE

Remove a table

DROP TABLE table_name;

Clear table of ALL records

TRUNCATE TABLE table_name;

Clear table of SOME records

DELETE FROM table_name WHERE condition;
Applying SQL to Real-World Problems

DELETE inactive customers

Desired Modification: Remove customers who are no longer active

DELETE FROM customer
WHERE active = FALSE;
Applying SQL to Real-World Problems

DELETE using a subquery

Desired Modification: Removing all customers who live in the city of Woodridge.

DELETE FROM customer
WHERE address_id IN 
  (SELECT address_id 
   FROM address
   WHERE city = 'Woodridge');
Applying SQL to Real-World Problems

Let's DELETE some records!

Applying SQL to Real-World Problems

Preparing Video For Download...