Exercise: Create Database and Relationships
https://classroom.google.com/u/0/c/NDgwNDYwMTI2OTAz/a/NTE0OTI2NTkxNjU0/details
- Users, Products, Orders and Categories
- Needed a Details table for the many to many relationship between Products and Orders
- new users
- new categories (order changed because we need to insert categories before products)
- new products
- new orders (inserted orders and details)
- change name of one product by id
- change price of one product (we update the product and the details with that product)
- Trying to delete a product will trigger an constraint error, because that
product is referenced as FK in the table
details
.
- We need to delete the referencing line before deleting the product.
- Add new table
reviews
.
- Add new reviews.
- Get all reviews
- Get all products, with their reviews
We understand that all products implies a LEFT JOIN
.
- Another example, with average ratings.
- Get a product with its reviews
- Get products with category and reviews
We choose, again, a LEFT JOIN
.
- A user and their orders with details
- Delete a review by
id
.
In this BD, the reviews have no id
. They are referenced as PK by the
combination (user_id,product_id)
.
But it's easy to add an id
(the exercise never says that it must be a PK).
And then, use the id
to delete a review.