[英]Inserting records in a primary;foreign key columns from another table
EDIT: It's seemingly the term 'bridging tables' got what I need
编辑:看来“桥接表”一词满足了我的需求
I'm trying to insert a record in a table produ_tag
with a primary and foreign key as columns. 我正在尝试在表
produ_tag
插入一条记录, produ_tag
主键和外键作为列。
produ_tag produ_tag
products 制品
tags 标签
The first column refHe
is the code of the product from products
table, the second contains the tag for the product from tags
table. 第一列
refHe
是products
表中产品的代码,第二列包含tags
表中产品的tags
。 The modeling software made this additional table so it can saves which product contains which tag which is necessary. 建模软件制作了这个附加表,因此可以保存哪个产品包含哪个标签是必需的。
The problem is they're primary, so if I have a product with 2 tags, the record won't be inserted, as it has already the same product inserted previously. 问题是它们是主要的,所以如果我有一个带有2个标签的产品,则不会插入该记录,因为它已经插入了与以前相同的产品。
Should I delete the primary thing for both? 我应该同时删除两者的主要内容吗? Or there is another way to handle this, as the modeling software rendered it that way.
还是有另一种方法可以处理此问题,因为建模软件以这种方式进行了渲染。
The produ_tag
table is a "bridging table", and the the composite primary key will allow any number of tags ( namCh
) to be associated with a product ( refHe
), provided that the tag exists in the tags
table and that the (refHe, nameCh)
pair is unique (ie you can't associate the same product and tag more than once). produ_tag
表是一个“桥接表”,并且复合主键将允许将任意数量的标签( namCh
)与产品( refHe
)关联,只要该标签存在于tags
表中并且(refHe, nameCh)
对是唯一的(即,您不能将同一产品关联并标记多次)。
If you get an error trying to insert a tag, it's not due to a faulty PK setup. 如果您在尝试插入标签时遇到错误,则不是由于PK设置错误所致。 You're either trying to reference a tag that doesn't exist, or you're inserting a combination of values that are already present in the table.
您正在尝试引用不存在的标记,或者正在插入表中已经存在的值的组合。
Don't delete your primary keys. 不要删除您的主键。 The only obvious problem I see is that there's no FK constraint from
produ_tag.refHe
to products.refHe
. 我看到的唯一明显的问题是,从
produ_tag.refHe
到products.refHe
没有FK约束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.