Deleting Data

Another step you can easily take on existing data is to entirely remove it from the database. To do this, you use the DELETE command.

DELETE FROM tablename WHERE
→ column='value'

Note that once you have deleted a record, there is no way of retrieving it, so you may want to back up your database before performing any deletes. Also, you should get in the habit of using WHERE when deleting data, or else you will delete all of the data in a table. The query DELETE FROM tablename will empty out a table, while still retaining its structure. Similarly, the command TRUNCATE TABLE tablename will delete an entire table (both the records and the structure) and then re-create the structure. The end result is the same, but this method is faster ...

Get PHP and MySQL for Dynamic Web Sites: Visual Quickpro Guide, 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.