user16790886
user16790886

Reputation:

Removing All Elements From a Databases Python

I built this program and can't seem to figure out how to remove all of the elements from the database. My code is below:

def clear_books():
c = cursor()
with c.connection:
    for book in c.execute("SELECT * FROM books"):
        c.execute("DELETE FROM books WHERE title=?", (book[0],))

If anyone can figure this out I would be very grateful.

Upvotes: -1

Views: 286

Answers (1)

Tim Roberts
Tim Roberts

Reputation: 54787

Skip the loop and do

c.execute("DELETE FROM books;")

Upvotes: 1

Related Questions