【问题标题】:Inheritance in table creation in SQL [duplicate]SQL中表创建的继承[重复]
【发布时间】:2020-09-03 08:29:11
【问题描述】:

我想创建 WorkerStudent 表,其中包含很多类似的信息(名字、第二名等),所以我要提取另一个类似于名为 Person 的抽象表,其中将包含 WorkerStudent 表的一般信息。

最好的方法是什么?

我还需要 id 是唯一的,即 Worker 表和 Student 表中的 id 不同。

【问题讨论】:

    标签: sql sql-server


    【解决方案1】:

    使用所有组合信息和person_id 创建一个表persons

    创建两个额外的表,workersstudents。这些表的主键是persons 表的外键:

    create table students (
        student_id int primary key references persons (person_id),
        . . .
    );
    
    create table workers (
        worker_id int primary key references persons (person_id),
        . . .
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-28
      • 2019-04-13
      相关资源
      最近更新 更多