relational databases?

hello im trying to make two databases linked for a book review system im creating

for example i have a table for books and i also have another table for genres.

The books table will store all the different books and will have a foreign key of the genre it belongs to using a genre_id key or something.

When i do a query for genres i want it to display how many books are in that genre eg 2 books in the fantasy genre.

for that i would need a records column? but how do i have that auto incrementing/deleting whennew records are added or deleted?

If you are using MySQL I would set it up pretty much like this

books
id
isbn
year
title
synopsis

genres
id
title
description

[hr]

Then you must decide how you should link these tables. If you will have a one - one relation, you can add genre_id to books, so it becomes

books
id
isbn
genre_id
year
title
synopsis

genres
id
title
description

This however means that one book can only have one genre, it can not be in sci-fi and action.

[hr]

In order to get a one - many relation, you should set up another table. You will end up with something like this:

books
id
isbn
genre_id
year
title
synopsis

genres
id
title
description

book_x_genre
book_id
genre_id

[hr]

Kinda hard to advise on any queries as we don’t know what database you are using.

Sponsor our Newsletter | Privacy Policy | Terms of Service