如何将用户绑定到具有不同角色的不同组织、大学、公司?

How to bind users to different organizations, universities, companies with different roles?

          USERS

 1. GFER: SUPERADMIN

Foundation(VAG):
  2. John: Incharge
  3. Jessi: IT Head

University(MIT):
 4: Bill: Adminstrator
 5: Gates: Prinicipal investigator
 6: Donald: Researcher

Organizations(YE):
 6. Jason: Head of R&D
 7. Johnny: Researcher

大学、组织或公司不能没有用户而存在。总会有一个用户创建或拥有它。每个用户也会有个人资料。

架构如下所示:

用户

- email
- name

角色:

 - id
 - name

大学(简介):

 - name
 - short history

组织(简介):

  - name
  - logo of the brand

基金会(简介):

  - name
  - Adminstrative contacts

我如何知道用户绑定到哪个 table(基金会、组织或大学)以及它在该组(基金会、组织或大学)中扮演什么角色?我想像这样创建一个桥梁 table:

  Group:
    - id
    - name
    - type(University, Foundation, Organization)
  
 Group_members:
   - id
   - roleId
   - groupId
   - userId

但问题是我无法创建 groups table,因为大学、基金会和组织的数据彼此完全不同。所以我必须为每个创建一个单独的 table。我该如何解决这个问题?

-- User USR exists.
--
user {USR}
  PK {USR}
-- Role ROL exists.
--
role_ {ROL}
   PK {ROL}

Xorg 是大学、组织或基金会的通用术语。 鉴别器TYP就是用来区分这三者的。

-- Xorg XOG, of type TYP, named XNM was created
-- (is owned) by user USR.
--
xorg {XOG, TYP, USR, XNM, ...common_cols}
  PK {XOG}
  SK {XOG, TYP}

CHECK TYP in {'U', 'O', 'F'}

FK {USR} REFERENCES user {USR}
-- University (xorg) XOG, of xorg-type TYP = 'U', exists.
--
university {XOG, TYP, ...university_specific_cols}
        PK {XOG}

CHECK TYP = 'U'

FK {XOG, TYP} REFERENCES xorg {XOG, TYP}
-- Organization (xorg) XOG, of xorg-type TYP = 'O', exists.
--
organization {XOG, TYP, ...organization_specific_cols}
          PK {XOG}

CHECK TYP = 'O'

FK {XOG, TYP} REFERENCES xorg {XOG, TYP}
-- Foundation (xorg) XOG, of xorg-type TYP = 'F', exists.
--
organization {XOG, TYP, ...foundation_specific_cols}
          PK {XOG}

CHECK TYP = 'F'

FK {XOG, TYP} REFERENCES xorg {XOG, TYP}
-- User USR is member of xorg XOG, of xorg-type TYP,
-- in role ROL.
--
user_xorg {USR, XOG, TYP, ROL}
       PK {USR, XOG}

      FK1 {XOG, TYP} REFERENCES
     xorg {XOG, TYP}

      FK2 {USR} REFERENCES user  {USR}
      FK3 {ROL} REFERENCES role_ {ROL}

注:

All attributes (columns) NOT NULL

PK = Primary Key
AK = Alternate Key   (Unique)
SK = Proper Superkey (Unique)
FK = Foreign Key

关于 亚型 的一句话。为子类型实现约束的正确方法是使用断言(CREATE ASSERTION),但它在主要数据库中仍然不可用。我正在使用 FKs 代替,并且与所有其他替代方法一样,它并不完美。人们争论很多,关于 SO 和 SE-DBA,哪个更好。我鼓励您也检查其他方法。