MySQL Forums
Forum List  »  Newbie

Re: Triggers
Posted by: Peter Brawley
Date: March 25, 2022 10:32AM

Quote

there is only one version of each book available in my library and it can only be borrowed to one person at a time. I thought about solving this with a trigger, would that work? I'm really grateful for your input and hints!

Usually it's better to build likely future changes into a db design. The ways books are, you're likely to eventually have more than one version of some book(s). The ways people are, you'll likely have multiple John Smiths. The way the world goes, you may need someday to add another type, eg intern. So books & persons need IDs that are guaranteed unique, and you appear to need something like ...

authors( aID, name )
books( bID, title, edition, date, ... )
bookauthors( aID, bID )
persontypes( typeID, typename )
persons( pID, name, typeID, email, ... )
borrowings( bID, pID, dateborrowed, datereturned )

... then an Insert Trigger on borrowings could be coded to refuse to add a row for a book that's out and an Update Trigger on borrowings could be coded to refuse to update a return date on a book that's not out.

Options: ReplyQuote


Subject
Written By
Posted
March 25, 2022 06:27AM
March 25, 2022 08:10AM
Re: Triggers
March 25, 2022 10:32AM


Sorry, you can't reply to this topic. It has been closed.
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.