Get startedGet started for free

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!

This exercise is part of the course

Introduction to Databases in Python

View Course

Exercise instructions

  • Drop the state_fact table by applying the method .drop() to it and passing it the argument engine (in fact, engine will be the sole argument for every function/method in this exercise!)
  • Check to see if state_fact exists via print. Use the .exists() method with engine as the argument.
  • Drop all the tables via the metadata using the .drop_all() method.
  • Use a print statement to check if the census table exists.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Drop the state_fact table


# Check to see if state_fact exists
print(____)

# Drop all tables


# Check to see if census exists
print(____)
Edit and Run Code