UML of DataBase

Viewed 73

I am going to create web app where the users can rate books, add a chapter of book to their cart, buy then download. Here is my uml of db. book and chapter have “one to many” relationship, but I created composite primary key from foreign key of book id b_id and chapter id c_id to identify chapters number in the books. chapter and user have “many to many” relationship, because one chapter can be bought by many users and one user can buy many books. And I created “many to many” relationship between book and user tables for 5 star rating system. Is it bad that the book separately also has a relationship with user table and I have to choose between chapter and rating (user_m2m_book) tables.

I'm not sure if my schema is in 3rd normal form. Could such a composite primary key as in the user_m2m_chapter table lead to some serious problems? Any other mistakes in my schema?

I know that many decisions have to made based on the subject area. But I am doing it for myself and asking for advice.

1 Answers

Not the expert, but I think rather than linking chapter to the user establish a relation between user and book with "Many-to-Many" relationship. And, also create a relationship between book and chapter same "Many-to-Many". This way User and Book will have relationship and with the help of JOIN you can get the chapter as well via BookId in Chapter's table. Note: Better if you create one table where you can store user and book information where same user will have many books id or vice-versa.

Related