本文介绍了实体关系-弱者是否可以像“一个”一样参与“一对多”关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下实体关系结构,我正在努力弄清贷款实体和ITEM实体之间的关系是否有效?

With the following entity relationship structure I'm struggling to figure out if the relationship between the LOAN and ITEM entities is valid?

贷款弱的实体使用a loan_dateLeant的部分键以及来自CUSTOMER和ITEM的主键,以形成LOAN的主键。
但是,贷款与ITEM之间存在一对多关系,因为贷款可以包含多个项目。
但是可以肯定的是,这意味着如果借出了多个项目,则贷款记录的主键部分将具有两个item_id值?

The weak entity of LOAN uses a partial key of 'loan_dateLeant' and the primary keys from CUSTOMER and ITEM to form LOANs primary key.However LOAN has a 'one to many' relationship with ITEM as a loan can consist of more than one item.But surely this means that if more than one item is loaned, then the loan record will have two item_id values for part of its primary key?

推荐答案

是的,那是无效的-您不能使用一对多关系作为主键的定义部分。相反,您可能考虑添加唯一的 loan_id 作为主键的一部分,而不是贷款包含的项目;那么单笔贷款将由其客户和贷款ID(或客户,日期和贷款ID)定义。

You're right, that's not valid - you can't use a to-many relationship as a defining part of a primary key. What you might consider doing instead is adding a unique loan_id that you make part of your primary key, instead of the items the loan contains; then a single loan is defined by its customer and loan ID (or customer, date, and loan ID).

如果这不起作用,则使 date_leant 一个datetime字段,并提高其精度,直到您不可能(在系统的约束范围内)同时发生两笔借贷-一次借贷的可能性有多大客户在毫秒之内进行两次单独的贷款交易?

If that doesn't work, make date_leant a datetime field, and increase the precision on it until you can't possibly (within the constraints of your system) have two loans occur at the same time - how likely is it that a single customer transacts two separate loans within milliseconds of each other?

请注意,这并不妨碍LOAN实体以一个的身份参与该关系;这只是意味着您无法使用许多来定义弱实体。

Note this doesn't prevent the LOAN entity from taking part in the relationship as the "one"; it just means that you can't define the weak entity using the "many".

这篇关于实体关系-弱者是否可以像“一个”一样参与“一对多”关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-05 03:33