May-18-2018, 07:16 PM
I currently use an Excel sheet to run a library inside of a prison but I think I'd like a better tool for the job so I'm trying to create it. My current plan is to write the program as a command line only program then come back later and write a GUI for it using Tk.
I'v pasted below the table layout I think I need but I'm having trouble figuring out how to link the Books table and the Authors Table considering that each book can have more than one author and each author can write more than one book. Any pointers here?
Also, I'm not a skilled programmer or database admin by any stretch, so even a few examples on how to create my tables with primary and foreign keys would be much appreciated. Thanks.
Books
*book_id (PK) unique numeric id for each book, exampe, 0001, 0002, 0048, etc...
*author_id (FK -> Authors) unique id for each author
*book_title title of the book
*genre genre of the book
*type hardback, softback, or paperback
*cover Y, N, S, or -
*price price of the book
*count holds the number of times the book and been checked out, increments on each checkout
Authors
*author_id (PK) unique id for each author
*first_name first name of author, (note that books can have more than one author)
*last_name last name of author, (note that books can have more than one author)
Checkout
*book_id (FK -> Books) unique numeric id for each book, exampe, 0001, 0002, 0048, etc...
*inmate_number inmates 8 digit prison number (00123456)
*checkout_date date book was checked out
*due_date due date, number of days from checkout, can be hard coded or read from a config file
Charged
*book_id the id of the book when it was charged, not a FK as the IDs will be reused after a set period of time
*checkout_date date of checkout not a FK
*due_date due date, not a FK
*charge_date date charge was entered
*inmate_number inmates 8 digit prison number (00123456) not a FK
Discarded
*book_id hold the ID's of the books I have retired for wear and tear, IDs can be reused immediately, not a FK
*book_title title of book, not a FK
*date date book was discarded
VisitLog
*inmate_number inmates 8 digit prison number (00123456), not a FK, entered at time of checkout from the checkout table
*date date of visit, entered at time of check from the checkout table
MainDisplay
(This is the main screen I would be looking at when opening up the program, the sheet you would see if all this was being done from Excel, I think this table should run in memory)
*book_id (FK -> Books) unique numeric id for each book, exampe, 0001, 0002, 0048, etc...
*first_name first name of author (read from authors table)
*last_name last name of author (read from authors table)
*book_title title of book (read from Books table)
*genre genre of book (read from Books table)
*cover Y, N, S, or - (read from Books table)
*price price of book (read from Books table)
*inmate_number inmate_number (read from checkout table)
*checkout_date date book was checked out (read from checkout table)
*due_date due date (read from checkout table)
I'v pasted below the table layout I think I need but I'm having trouble figuring out how to link the Books table and the Authors Table considering that each book can have more than one author and each author can write more than one book. Any pointers here?
Also, I'm not a skilled programmer or database admin by any stretch, so even a few examples on how to create my tables with primary and foreign keys would be much appreciated. Thanks.
def build_db(self): conn = sqlite3.connect(r"C:\\Users\\bi18avi\\librarydb\\booksdb") c = conn.cursor() c.execute('''CREATE TABLE Books (book_id INT, author_id INT, book_title TEXT, genre TEXT, type TEXT, cover INT, price REAL)''') conn.commit()DATABASE
Books
*book_id (PK) unique numeric id for each book, exampe, 0001, 0002, 0048, etc...
*author_id (FK -> Authors) unique id for each author
*book_title title of the book
*genre genre of the book
*type hardback, softback, or paperback
*cover Y, N, S, or -
*price price of the book
*count holds the number of times the book and been checked out, increments on each checkout
Authors
*author_id (PK) unique id for each author
*first_name first name of author, (note that books can have more than one author)
*last_name last name of author, (note that books can have more than one author)
Checkout
*book_id (FK -> Books) unique numeric id for each book, exampe, 0001, 0002, 0048, etc...
*inmate_number inmates 8 digit prison number (00123456)
*checkout_date date book was checked out
*due_date due date, number of days from checkout, can be hard coded or read from a config file
Charged
*book_id the id of the book when it was charged, not a FK as the IDs will be reused after a set period of time
*checkout_date date of checkout not a FK
*due_date due date, not a FK
*charge_date date charge was entered
*inmate_number inmates 8 digit prison number (00123456) not a FK
Discarded
*book_id hold the ID's of the books I have retired for wear and tear, IDs can be reused immediately, not a FK
*book_title title of book, not a FK
*date date book was discarded
VisitLog
*inmate_number inmates 8 digit prison number (00123456), not a FK, entered at time of checkout from the checkout table
*date date of visit, entered at time of check from the checkout table
MainDisplay
(This is the main screen I would be looking at when opening up the program, the sheet you would see if all this was being done from Excel, I think this table should run in memory)
*book_id (FK -> Books) unique numeric id for each book, exampe, 0001, 0002, 0048, etc...
*first_name first name of author (read from authors table)
*last_name last name of author (read from authors table)
*book_title title of book (read from Books table)
*genre genre of book (read from Books table)
*cover Y, N, S, or - (read from Books table)
*price price of book (read from Books table)
*inmate_number inmate_number (read from checkout table)
*checkout_date date book was checked out (read from checkout table)
*due_date due date (read from checkout table)