数据库和深层复制 [英] Databases and Deep Copy

查看:97
本文介绍了数据库和深层复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我发现自己想做一个存储在我的关系数据库中的一个对象的深层拷贝,那么我一定在建筑上从根本上错误地做错了吗?这是另一个不同的角度(更详细的)我问的问题,但没有得到很多回应称为复制关系表数据

解决方案

这取决于你的关系表所代表的,你的实体是组合在一起构建业务对象。例如,如果您有一个内容管理系统的关系模型,其中包含Postings表和Text_lines表,其中每个Posting都包含一个文本行列表,那么您的业务对象发布的有效副本很有可能作为Postings实体的深层副本与所属的Text_lines实体。另一方面,有两个表部门和员工,一个部门的正确副本很可能不是一个深层次的副本(至少如果每个员工在一个时间点与一个部门相关联)。在关系数据库方案中,这些差异往往与分配给关系的引用完整性检查并行。可以使用具有ON DELETE CASCADE完整性的外键约束来建模Postings - >Text_lines关系(当然,如果您的数据库支持的话)。然而,部门 - >员工不应该有这样的ON DELETE CASCADE检查。


If I find myself wanting to do a deep copy of an object stored in my relational database, have I necessarily done something fundamentally wrong architecturally? This is a different angle on another (much more detailed) question I asked, but haven't gotten much response to called Copying Relational Table Data.

解决方案

It depends on what your relational tables represent, and which of your entities are grouped together to build a "business object". For example, if you have a relational model of a content management system with a table "Postings" and a table "Text_lines" where every Posting consists of a list of text lines, a valid copy of your business object "Posting" will most likely be a deep copy of a "Postings" entity together with the belonging Text_lines entities.

On the other hand, having two tables "Department" and "Employees", a correct copy of a department most likely is not a deep copy, (at least, if each employee is associated with exactly one department at one point in time). In a relational database scheme, those kind of differences will often go hand-in-hand with referential integrity checks assigned to the relations. The relation "Postings"->"Text_lines" can be modeled using a foreign key constraint with an "ON DELETE CASCADE" integrity (of course, if your database supports that). The "Department"-> "Employees", however, should not have such an "ON DELETE CASCADE" check on it.

这篇关于数据库和深层复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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