linking databases.

Hi im trying to build a database for a web service where authors submit books which can be reviewed by a normal user.

So i understand i need two tables one for users and one for authors. I would also need a table to hold all the books information and then another one to hold all the reviews so thats four tables.

how would i go about linking the reviews to the books but these should be allowed to be deleted by the user who posted the review and the book deleted by the author who posted the book only.

Any ideas :stuck_out_tongue: ive just confused myself :o

You are probably using MySQL which is a relational database. Relations are usually made with linking tables with foreign keys.

All of your tables should have an auto incrementing id column. We later use these ids to link stuff together.

Then in the review table you simply add book_id and user_id. And when inserting a new review you simply insert the id of the book the user is writing the review for, and the user id of that user.

Later you can also join these tables together so you can get data from all three tables in a single query if you want.

thanks you made it sound easy as in i should have been able to figure that out kinda easy

thanks again

Yea well, if you’re new to something it takes a while getting into the way of thinking. Then one day it just all start to make perfect sense :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service