Delete data

DELETE removes rows from a table. The big thing to respect here is the WHERE clause, because that is what decides which row or rows will be deleted.

So the shape is simple: DELETE FROM table_name WHERE condition. If the condition matches one row, one row gets deleted. If it matches several, several get deleted. And if you forget the WHERE entirely, MySQL deletes every row in the table. That is the dangerous part of this lesson.

So the main mental note is not really the syntax – it is the caution. DELETE is easy to write, but the condition matters a lot more than with SELECT, because now you are changing data instead of only reading it.

The flow is still familiar: connect, write the SQL, run it, check whether it worked, then close the connection. The only new shift is that this query removes data instead of returning it.