你好,我在我的实体关系图(ER(上有2个实体,分别是客户和产品。
客户和产品有一个 M 到 N 的关系,即 RATE,这种关系有 2 个属性,即评论和费率。
我的产品实体有一个名为 Rating-avg 的派生属性,它是产品的平均评级,由客户的评级。
我不知道也找不到如何在创建或更改时将派生属性添加到表中。
如果有人能帮忙,我会很高兴。
我正在使用SQLite3(3.25.2(和SQLiteStudio(3.2.1((最新版本(。
您将使用第三个表,称为"联结"或"关联"表:
create table CustomerProducts (
CustomerProductId int primary key,
CustomerId int references customers(CustomerId),
ProductId int products(productId),
Rate ?, -- unclear what the type is
Comment text
);
如果您愿意,可以将该表命名为Rate
。我通常以关系中涉及的两个表命名关联表,除非它本身就是实体。