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. What this means is that we delete data in one table but somehow do not delete the related data in another SQL table.

If we create our quotations table without a foreign key relationship to the books table, we can end up with orphan records:

        # create second Table inside DB --          # No FOREIGN KEY relation to Books Table         cursor.execute("CREATE TABLE Quotations (                  Quote_ID INT AUTO_INCREMENT,                       Quotation VARCHAR(250),                            Books_Book_ID INT,                                 PRIMARY KEY (Quote_ID)                         ) ENGINE=InnoDB")

After inserting data into the books and quotations tables, if we execute a DELETE statement, ...

Get Python GUI Programming Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.