I have the following schematic
Book
id INT(12), // PK
title VARCHAR(50),
isbn VARCHAR(50),
price VARCHAR(8),
image VARCHAR(200)
Book_Genre
book_id INT(12), // COMPOUND KEY also references Book.id
genre_id INT(12) // COMPOUND KEY also references Genre.id
Book_Classification
book_id INT(12), // PK + FK, references Book.id
classification_id INT(12) // FK, references classification.id
Genre
id INT(12), // PK
title VARCHAR(50)
Classification
id INT(12), // PK
classification_type VARCHAR(20),
classification_description VARCHAR(200),
classification_value VARCHAR(12)
Where Book_Genre
and Book_Classification
act as join
tables from Book
. Technically with this current approach a Book can have a Genre and a Classification if both join
tables are populated with the book_id (Book.id)
. The problem with this is that a book with a Classification is considered a NonFiction book, and a book with a Genre is considered to be a Fiction book.
I'm insistent on keeping the join
tables as it allows me to give multiple Fiction books multiple genres, i.e. Action & Horror, and it allows me to give NonFiction books multiple classifications, such as their LOC numbers and their DeweyDecimal values.
Is it possible to limit a relation/reference to one table if a relation/reference to another table already exists?
To clarify:- I don't want a Book to be able to be given a classification if it already has a genre, and I don't want a book to be able to be given a genre if it already has a classification.
(Sorry for the naff schematic, not on my work PC)