2

Hello I have 2 entities that are CUSTOMER and PRODUCT at my Entity Relation Diagram(ER).

CUSTOMER and PRODUCT has a M to N relationship which is RATE and this relationship has 2 attributes which are Comment and Rate.

My PRODUCT entity has a derived attribute named Rating-avg which is the average rating of the product, being rated by the CUSTOMER's.

I don't know and can't find how to add the derived attribute to the table while creating it or altering it.

I would be really glad if someone could help.

I am using SQLite3(3.25.2) and SQLiteStudio(3.2.1) (The latest versions up to date.).

BUY
  • 705
  • 1
  • 11
  • 30

1 Answers1

0

You would use a third table, which is called a "junction" or "association" table:

create table CustomerProducts (
    CustomerProductId int primary key,
    CustomerId int references customers(CustomerId),
    ProductId int products(productId),
    Rate ?,  -- unclear what the type is
    Comment text
);

You could name the table Rate, if you like. I typically name association tables after the two tables involved in the relationship, unless it is an entity itself.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786