数据库设计帮助

时间:2011-08-04 14:01:16

标签: sql database-design

我正在设计一个可以保存合同和保修的数据库。保修可以链接到合同,但不依赖于合同的存在。如何定义2?

之间的关系

3 个答案:

答案 0 :(得分:1)

这听起来像是在合同和保修之间建立关系表的地方。

表:Contract_Warrantee_Rel

int RelationshipID
int ContractID
int WarranteeID

答案 1 :(得分:1)

假设合同必须链接到一个保修单,我有2个表:

Contract
  ContractId  (Primary key)
  WarrantyId  (foreign key to Warranty'Warranty_Id
  ...
  ...

Warranty
  Warranty_Id  (Primary key)
  ...
  ...

另一方面,如果合同可以链接到无保险或超过1保修,那么我会改为使用联结表:

Contract
  ContractId  (Primary key)
  ...
  ...

Warranty
  Warranty_Id  (Primary key)
  ...
  ...

ContractWarranty
  ContractId  (Primary key) (Foreign key to Contract table)
  Warranty_Id (Primary key) (Foreign key to Warranty table)

答案 2 :(得分:0)

contract
--------
contract_id Number NOT NULL / Unique
other_stuff

warranty
---------
warranty_id  Number NOT NULL / Unique
contract_id
more_stuff

除非保修可以某种方式属于多个合同..那么你需要一个像这样的关联类:

warranty_contract
-----------------
warranty_id
contract_id
effective_dt
other info..