0

我的系统需要两种不同的客户类型。我需要一个个人和企业客户。我将如何在 Apex 中创建表?

我需要一个客户、个人和公司表还是只需要一个客户和公司表?

该系统适用于汽车租赁。

我需要的属性是:客户 ID、名字、姓氏、地址、邮政编码、电话号码、公司名称、频率(这是针对公司实体的,基于他们雇用的频率)。

4

1 回答 1

0

公司名称属于公司,不属于个人客户;因此,请创建一个Corporations表,然后在外键中为您的企业客户引用该表。您还可以从数据中分离出核心Customer数据CorporateCustomer并将它们存储在单独的表中:

Oracle 18c 设置

CREATE TABLE Customers (
  id           NUMBER(10,0)
               GENERATED ALWAYS AS IDENTITY
               CONSTRAINT Customers__id__pk PRIMARY KEY,
  first_name   VARCHAR2(200)
               CONSTRAINT Customers__firstname__nn NOT NULL,
  surname      VARCHAR2(200)
               CONSTRAINT Customers__surname__nn NOT NULL,
  post_code    VARCHAR2(7)
               CONSTRAINT Customers__postcode__nn NOT NULL,
  phone_number VARCHAR2(15)
               CONSTRAINT Customers__phone__nn NOT NULL
);

CREATE TABLE Corporations(
  id           NUMBER(10,0)
               GENERATED ALWAYS AS IDENTITY
               CONSTRAINT Corporations__id__pk PRIMARY KEY,
  name         VARCHAR2(500)
               CONSTRAINT Corporations__name__nn NOT NULL
);

CREATE TABLE Corporate_Customers (
  id           NUMBER(10,0)
               CONSTRAINT CorporateCustomers__id__pk PRIMARY KEY
               CONSTRAINT CorporateCustomers__id__fk REFERENCES Customers(id),
  corporation  NUMBER(10,0)
               CONSTRAINT CorporateCustomers__corp__nn NOT NULL
               CONSTRAINT CorporateCustomers__corp__fk REFERENCES Corporations(id),
  frequency    NUMBER(10,0)
               CONSTRAINT CorporateCustomers__freq__nn NOT NULL
               CONSTRAINT CorporateCustomers__freq_gte_0__chk CHECK ( frequency >= 0 )
);

db<>小提琴

于 2019-12-05T21:04:54.963 回答