MySQL-如何将外键约束添加到两列主键?

时间:2019-04-10 06:26:56

标签: mysql foreign-keys primary-key database-schema

我有一个数据库驱动的Web应用程序,正在开发中,以跟踪projects总体上一个或多个organization的实体的状态

  

注意:这实际上是一种开发实践,是独立的   我正在进行的项目。现在这是我自己的项目。

一个organization具有多个projects,其中每个项目都有多个entities并与一个项目相关联的types分类。

识别出的实体是

  • 操作项
  • 问题
  • 风险
  • 机会

所有实体之间都有联系...(引用以上各项的项,与我的实体相关的

基于以上这些实体,我具有以下表集。

*items  (this stores the primary key itemid along with a itemtypeid and resolveditemid) 
     itemtypeid is one of the four entity types
     resolveditemid is the actual primary key of any of the four entities above of the entity, determined by item type id

*projects  (one project has many items)

*itemtypes (one project has many item types, as classified by 1 - 4)

1) action items   (one project has many action items to be more specific)

2) issues  (one project has many issues ...)

3) risks  (one project has many risks)

4) opportunities  (one project has many opportunities ..)

我如何在项目项中约束itemtypeid和itemid,这些项目项组合起来进行查找时,可以解析为实际引用的目标记录,该目标记录位于actionitem,问题,风险...中?

>

到目前为止,我具有以下架构图:

Schema

0 个答案:

没有答案