SQL Exercises: DELETE
Delete Exercises
Now that we've got to grips with creating, reading and updating data in our database, it's time to watch the world burn 🔥.
**⚠️ In the world of databases, once something has been deleted it's gone for good. **
For these exercises, you should use the DELETE keyword if you want to be selective with your deletion.
If you want to be less discriminating, you can use DROP, the most dangerous of all the keywords.
- Write a statement to delete the keyword with
id
=839
from the eyword table. This is trickier than it seems. Remember that foreign key constraints prevent us from deleting records that are referenced in other tables. To get around foreign key constraints, you can: manually delete related records from other tables, alter the table to enable cascading deletes or remove foreign key constraints (temporarily or permanently). Think about the advantages and disadvantages of each of these options. - Delete any movies that are produced by the
"Cowboy Films"
production company. - Delete any movies that have a revenue of 0.
- Pick a person or actor from the
person
table, delete them and all the movies they are associated with or have played in. Consider foreign key constraints again! - Delete the entire
movie_languages
table. You might want to check the TRUNCATE command.