我如何在SQL中实现这3个简单的东西?

时间:2017-05-20 22:08:45

标签: sql database

我是一个绝对的SQL初学者,我已经用谷歌搜索了很多,但没有找到我需要的东西。那么我如何在SQL中实现(从ER模型翻译):

非常感谢

1 个答案:

答案 0 :(得分:1)

在Postgres中你有三个:

create table one 
(
  id integer primary key, 
  tags text[] -- can store multiple tags in a single column
);

可以通过记录类型完成具有多个属性的单个列:

create type address as (number integer, street varchar(100), city varchar(100));

create table customer 
(
  id integer primary key, 
  name varchar(100) not null,
  billing_address address
);

可以使用继承

完成isA关系
create table paying_customer
(
   paid_at timestamp  not null,
   paid_amount decimal(14,2) not null
)
inherits (customer);

付费客户拥有客户的所有属性以及付款发票的时间。