Using the SQL DELETE command
In this recipe, we will use the SQL DELETE
command to delete the data we created in the previous recipe, Using the SQL UPDATE command.
While deleting data might at first sight sound trivial, once we get a rather large database design in production, things might not be that easy any more.
Because we have designed our GUI database by relating two tables via a primary to foreign key relation, when we delete certain data, we do not end up with orphan records because this database design takes care of cascading deletes.
Getting ready
This recipe uses the MySQL database, tables, as well as the data inserted into those tables from the previous recipe, Using the SQL UPDATE command. In order to demonstrate how to create orphan records, we will have to change the design of one of our database tables.
How to do it…
We kept our database design simple by using only two database tables.
While this works when we delete data, there is always a chance of ending up with orphan records...