基本表结构问题
我有品牌和公司。 1 个公司可以拥有 1 个或多个品牌。
例如,公司有company_id、company_name。同样,品牌有brand_id 和brand_name。现在我可以将FK列company_id也添加到品牌中,并且关系在2个表中完成,还是我需要像Company_Brands这样的第三个表,其中将包含company_id、brand_id和默认PK?
我并不是要求一种理想的教科书方式来完成此操作,而是在高事务环境中,性能很重要,因此查询污点较少,而且写入量会很高,表中的数据也会发生变化,因为这是一个用户内容站点,所以信息可能不准确,因此需要不断编辑。
I have Brand and Company. 1 Company can have 1 or more Brands.
As an example, company has company_id, company_name. Similarly Brands has brand_id and brand_name. Now can i add the FK column company_id to brands also and the relationship is complete in 2 tables or do i need a 3rd table like Company_Brands which will have company_id, brand_id and the default PK?
I am not asking for an ideal text book way this should be done but in a high transaction environment where performance is important so less query stain and also where writes will be high along with data will change in tables as this is a user content site so information may not be accurate and thus edited constantly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需将外键 company_id 添加到 Brands 表中即可。您描述了一对多的关系,即 1 个公司可以拥有多个品牌,但 1 个品牌不能拥有多个公司。
如果存在多对多关系,则仅需要联结表。
Just add the foreign key company_id to the brands table. You have described a 1 to many relationship i.e. 1 company can have many brands, but 1 brand cannot have many companies.
You would only need the junction table if you had a many to many relationship.