Deleting a table completely
You're now going to practice dropping individual tables from a database with the .drop() method, as well as all tables in a database with the .drop_all() method!
As Spider-Man's Uncle Ben (as well as Jason, in the video!) said: With great power, comes great responsibility. Do be careful when deleting tables,
as it's not simple or fast to restore large databases! Remember, you can check to see if a table exists on an engine with the .exists(engine) method.
This is the final exercise in this chapter: After this, you'll be ready to apply everything you've learned to a case study in the final chapter of this course!
Cet exercice fait partie du cours
Introduction to Databases in Python
Instructions
- Drop the
state_facttable by applying the method.drop()to it and passing it the argumentengine(in fact,enginewill be the sole argument for every function/method in this exercise!) - Check to see if
state_factexists viaprint. Use the.exists()method withengineas the argument. - Drop all the tables via the
metadatausing the.drop_all()method. - Use a print statement to check if the
censustable exists.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Drop the state_fact table
# Check to see if state_fact exists
print(____)
# Drop all tables
# Check to see if census exists
print(____)