链接数据实体在更新时的完整性 [英] The Integrity of linked data entities on update

查看:56
本文介绍了链接数据实体在更新时的完整性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在更新时保持链接数据实体完整性的最佳实践是什么?

What is the best-practice for maintaining the integrity of linked data entities on update?

我的情况

  1. 我有两个实体:客户"和发票".[客户是定义和发票就是交易].
  2. 开具许多发票给客户端碰巧客户端信息需要改变例如他的帐单邮寄地址/位置更改或公司名称...等".
  3. 正常情况下,用户必须能够更新客户端信息保持完整性系统中的数据.
  4. 发票中的交易实体"我不只是存储客户ID,而是以及与客户有关的所有客户信息发票,例如客户名称,地址,联系",这是众所周知的存储数据的方法交易实体.
  5. 如果用户创建了新发票,则新的客户信息将是存储在发票记录中具有相同的客户端ID(非常很明显!).

我的问题

  1. 可以绑定数据实体吗来自不同地点的客户"插入和更新?[说明:如果我遵循从步骤1-4开始,我必须从创建新客户表时发票,但以更新/打印我的发票绑定客户端实体发票表,否则数据不会是一致或整数...所以我如何保持数据完整性在不创建意大利面条代码的情况下DAL处理此习惯数据绑定的要求???
  2. 我通过了一个保存所有以前的版本更新前的实体数据保留所有版本的历史记录".如果我想使用相同的方法避免自定义绑定在数据库设计方面做到这一点使用MYSQL"?[说明:一些版本为1.0的发票客户然后客户信息更新,其版本变为1.1和最后创建的新发票版本...所以跟随它很好吗这种方法?以及我应该如何设计我的实体/表以满足实体的要求版本和绑定?
  3. 请提供任何书籍或参考可以把我踢到右边方向?

谢谢

推荐答案

您需要做的就是保持表格原样.没错,您应该将客户信息存储在发票中,以获取物品运往的历史记录.更改时,除尚未发货的任何发票外,您不应更新此信息.为了维护此类信息,您需要在客户表上触发一个触发器,以查找尚未发货的发票并自动更新这些地址.

What you need to do is leave the table the way it is. You are correct, you should be storing the customer information in the invoice for history of where the items were shipped to. When it changes, you should NOT update this information except for any invoices which have not yet been shipped. To maintain this type of information, you need a trigger on the customer table that looks for invoices that have not been shippe and updates those addresses automatically.

如果要保存客户端信息的历史版本,正确的过程是创建审核表并通过触发器填充它.

If you want to save historical versions of the client information, the correct process is to create an audit table and populate it through a trigger.

在这种情况下,数据完整性仅是通过客户ID的外键实现的.id本身永远不会更改或不会被用户更改,并且应该是一个替代数字,例如整数.因为您不应该在实际发票中更改地址信息(除非未发货,否则最好更改它,否则产品将被发货到错误的位置),这足以保持数据完整性.这还使您可以查看物料的实际运送位置,但仍可以通过使用外键查询有关客户端的当前信息.

Data integrity in this case is simply through a foreign key to the customer id. The id itself should not ever change or be allowed to change by the user and should be a surrogate number such as an integer. Becasue you should not be changing the address information in the actual invoice (unless it has not been shipped in which case you had better change it or the product will be shipped to the wrong place), this is sufficent to maintain data integrity. This also allows you to see where the stuff was actually shipped but still look up the current info about the client through the use of the foreign key.

如果您有更改的客户(其他公司购买的商品),则可以在服务器上运行一个过程以更新旧记录的客户ID,或者创建一个表结构来显示哪些客户ID属于当前的父ID.如果您不打算谈论更改数百万条记录,那么第一种更容易做到.

If you have clients that change (compaies bought by other companies), you can either run a process onthe server to update the customer id of old records or create a table structure that show which client ids belong to a current parent id. The first is easier to do if you aren;t talking about changing millions of records.

这篇关于链接数据实体在更新时的完整性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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