Using DELETE
Just as data sometimes needs to be updated, sometimes it also needs to be removed from a database table. People get new jobs, products are discontinued, and so on. When the time comes to remove something from a table in our database, we use the DELETE
command. The basic syntax is as follows:
DELETE FROM <table_name> [WHERE <where_conditions>];
As with UPDATE
statements, the WHERE
part of a DELETE
statement is optional, but if we leave it off, the command will delete every row in the table, which is even more catastrophic than leaving off the WHERE
part in an UPDATE
statement, if such a thing is possible. Make it a habit to always include it.
As an example, let's delete the Spencer Kimball
employee:
DELETE FROM employees WHERE givenname="Spencer" ...
Get Getting Started with MariaDB - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.