数据库设计:循环依赖 [英] Database Design: Circular dependency

查看:104
本文介绍了数据库设计:循环依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象下面的数据库:



表'Companies'有字段id,name和flagship_product_id。
表'product'有字段id,name和company_id。



公司必须拥有旗舰产品(1:1的关系),所有产品都有一个公司(1:N关系)。



当使用诸如MyISM的存储引擎时,上述情况不应该有任何问题,但是当使用诸如InnoDB在插入新数据时出现问题。



除了允许初始INSERT的NULL关系外,什么是一个很好的解决方案?


$ b $总而言之,公司必须拥有一个旗舰产品。

解决方案

我不知道特定的数据库引擎,但是在原子插入和更新操作期间搜索一种临时挂起数据一致性检查或引用完整性的方法。


Imagine the following database:

Table 'companies' has fields id, name and flagship_product_id. Table 'products' have fields id, name and company_id.

A company must have a flagship product (1:1 relationship) and all products have one company (1:N relationship).

When using a storage engine such as MyISM, there shouldn't be any problem with the above scenario, but when using an engine such as InnoDB, problems result when INSERTing new data.

What is a good solution except allowing a NULL relationship for the initial INSERT?

To summarize, A company must have one flagship product.

解决方案

I don't know that particular database engine, but search for a way to temporarily suspend the data consistency checks or referential integrity during your atomic insert and update operations.

这篇关于数据库设计:循环依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆