简体   繁体   English

创建表如何键入多个主键

[英]Creating Table How to key in more than one primary key

My question is how to make this work basically an office and non office workers can have more than one loan but since our loan id primary key I can't more than one any ideas how to do this? 我的问题是如何使这项工作基本上成为办公室,而非办公室工作人员可以拥有多于一笔的贷款,但是由于我们的贷款ID主键,我不能不超过一个想法如何做到这一点?

  CREATE TABLE loaner 
  (
      l_id NUMBER(10) primary key,
      type VARCHAR2(20),
      no_days_overdue NUMBER(3),
      loan_start_date date,
      loan_end_date date,
      fine_imposed NUMBER(55),
      constraint loaner_uk unique (l_id, type),
      constraint chk_type check (type='office' or type='nonoffice')
    );

    commit;

CREATE TABLE office 
(
  office_id NUMBER(5) primary key,
  l_id NUMBER(10) ,
  type VARCHAR2(10),
  office_forname VARCHAR2(30),
  office_surname VARCHAR2(30),
  email VARCHAR2(50),
  address VARCHAR2 (100),
  constraint office_fk foreign key (l_id, type) references loaner (l_id, type),
  constraint office_type_chk check (type='OFFICE')
);
commit;

CREATE TABLE nonoffice 
(
  nonoffice_id NUMBER(5), 
  l_id NUMBER(5),
  type VARCHAR2(10),
  non_forname VARCHAR2(30),
  non_surname VARCHAR2(30),
  constraint nonoffice_loaner_fk foreign key (l_id, type) references loaner (l_id, type),
  constraint nonoffice_type_chk check (brw_type='nonoffice')
);
commit;
        CREATE TABLE loaner 
          (
              l_id NUMBER(10) primary key,
              type VARCHAR2(20),
              no_days_overdue NUMBER(3),
              loan_start_date date,
              loan_end_date date,
              fine_imposed NUMBER(55),
              office_id NUMBER(5),
              nonoffice_id NUMBER(5),
              constraint office_fk foreign key (office_id) references office(office_id),
              constraint nonoffice_fk foreign key (nonoffice_id) references nonoffice(nonoffice_id)
            );

            commit;

        CREATE TABLE office 
        (
          office_id NUMBER(5) primary key,
          l_id NUMBER(10) ,
          type VARCHAR2(10),
          office_forname VARCHAR2(30),
          office_surname VARCHAR2(30),
          email VARCHAR2(50),
          address VARCHAR2 (100),
        );
        commit;

        CREATE TABLE nonoffice 
        (
          nonoffice_id NUMBER(5) primary key, 
          l_id NUMBER(5),
          type VARCHAR2(10),
          non_forname VARCHAR2(30),
          non_surname VARCHAR2(30),
        );
        commit;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有多个主键的表的外键 - foreign key to a table having more than one primary key 拥有多个主键表约束是错误的吗? - Is it an error to have more than one primary key table constraint? Microsoft SQL表可以有多个主键吗? - Can a Microsoft SQL table have more than one Primary Key? 如果主键有多于一列,如何引用 SQL 表? - How to reference a SQL table if primary key has more than one column? 外键引用多个主键值(来自一个表)-Oracle SQL PLUS - Foreign key referring to more than one primary key values(from one table) - Oracle SQL PLUS SQL查询,用于选择具有多个指向主键表的链接的外键行 - SQL query for selecting foreign-key rows with more than one link to the primary-key table 是否可以在一个表中引用一个主键作为跨越两个以上表的外键约束? - Is it possible to reference a primary key in one table as a foreign key constraint across more than 2 tables? 无法在laravel中创建表“一般错误:1个表具有多个主键” - Can't create table in laravel “General error: 1 table has more than one primary key” 我可以在同一个 ER 模型中的多个表中使用身份作为主键吗 - Can I use identity for primary key in more than one table in the same ER model SQL - 我可以将表主键基于多个字段,要求第一个或第二个值的唯一性吗? - SQL - Can I base a table primary key on more than one field, requiring the uniqueness of first OR second value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM