2019-02-21 18:11:14 +01:00
|
|
|
CREATE TABLE articles (
|
2019-02-21 20:17:11 +01:00
|
|
|
id integer GENERATED BY DEFAULT AS IDENTITY,
|
2019-02-21 18:11:14 +01:00
|
|
|
description varchar(100) NOT NULL,
|
|
|
|
price integer NOT NULL,
|
|
|
|
CONSTRAINT articles_pkey PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE customers (
|
2019-02-21 20:17:11 +01:00
|
|
|
id integer GENERATED BY DEFAULT AS IDENTITY,
|
2023-05-18 09:09:05 +02:00
|
|
|
code varchar(20),
|
2019-02-21 18:11:14 +01:00
|
|
|
description varchar(200),
|
|
|
|
city varchar(200),
|
2020-01-04 12:53:53 +01:00
|
|
|
rating INTEGER,
|
2019-12-23 10:35:36 +01:00
|
|
|
NOTE BLOB SUB_TYPE 1,
|
2019-02-21 18:11:14 +01:00
|
|
|
CONSTRAINT customers_pk PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
|
2022-06-16 14:05:01 +02:00
|
|
|
CREATE TABLE CUSTOMERS_WITH_GUID (
|
|
|
|
IDGUID VARCHAR(38) NOT NULL,
|
|
|
|
CODE VARCHAR(20),
|
|
|
|
DESCRIPTION VARCHAR(200),
|
|
|
|
CITY VARCHAR(200),
|
|
|
|
NOTE BLOB SUB_TYPE TEXT,
|
|
|
|
RATING INTEGER,
|
|
|
|
CONSTRAINT CUSTOMERS_WITH_GUID_PK PRIMARY KEY (IDGUID)
|
|
|
|
);
|
|
|
|
|
2020-03-27 00:37:28 +01:00
|
|
|
CREATE TABLE customers_plain (
|
|
|
|
id integer NOT NULL,
|
|
|
|
code varchar(20),
|
|
|
|
description varchar(200),
|
|
|
|
city varchar(200),
|
|
|
|
note blob sub_type text,
|
|
|
|
rating smallint,
|
2020-06-25 22:54:57 +02:00
|
|
|
creation_time time,
|
|
|
|
creation_date date,
|
2020-03-27 00:37:28 +01:00
|
|
|
CONSTRAINT customers_plain_pk PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
|
2020-03-31 16:23:22 +02:00
|
|
|
CREATE TABLE customers_with_code (
|
|
|
|
code varchar(20) NOT null primary key,
|
|
|
|
description varchar(200),
|
|
|
|
city varchar(200),
|
|
|
|
NOTE BLOB SUB_TYPE 1,
|
|
|
|
rating smallint
|
|
|
|
);
|
|
|
|
|
2019-02-21 18:11:14 +01:00
|
|
|
CREATE TABLE order_details (
|
2019-02-21 20:17:11 +01:00
|
|
|
id integer GENERATED BY DEFAULT AS IDENTITY,
|
2019-02-21 18:11:14 +01:00
|
|
|
id_order integer NOT NULL,
|
|
|
|
id_article integer NOT NULL,
|
|
|
|
unit_price numeric(18,2) NOT NULL,
|
|
|
|
discount integer DEFAULT 0 NOT NULL ,
|
|
|
|
quantity integer NOT NULL,
|
|
|
|
description varchar(200) NOT NULL,
|
|
|
|
total numeric(18,2) NOT NULL,
|
|
|
|
CONSTRAINT order_details_pkey PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE orders (
|
2019-02-21 20:17:11 +01:00
|
|
|
id integer GENERATED BY DEFAULT AS IDENTITY,
|
2019-02-21 18:11:14 +01:00
|
|
|
id_customer integer NOT NULL,
|
|
|
|
order_date date NOT NULL,
|
|
|
|
total numeric(18,4) NOT NULL,
|
|
|
|
CONSTRAINT orders_pkey PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2022-11-21 15:20:18 +01:00
|
|
|
-- public.people definition
|
|
|
|
|
|
|
|
-- Drop table
|
|
|
|
|
|
|
|
-- DROP TABLE public.people;
|
|
|
|
|
2019-02-21 18:11:14 +01:00
|
|
|
CREATE TABLE people (
|
2019-02-21 20:17:11 +01:00
|
|
|
id integer GENERATED BY DEFAULT AS IDENTITY,
|
2019-02-21 18:11:14 +01:00
|
|
|
last_name varchar(100) NOT NULL,
|
|
|
|
first_name varchar(100) NOT NULL,
|
|
|
|
dob date NOT NULL,
|
|
|
|
full_name varchar(80) NOT NULL,
|
|
|
|
is_male BOOLEAN DEFAULT TRUE NOT NULL,
|
|
|
|
note blob sub_type TEXT,
|
|
|
|
photo blob sub_type binary,
|
2022-11-21 15:20:18 +01:00
|
|
|
person_type varchar(40),
|
|
|
|
salary number(18,4),
|
|
|
|
annual_bonus number(18,4),
|
2019-02-21 18:11:14 +01:00
|
|
|
CONSTRAINT people_pkey PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
|
2019-02-21 20:17:11 +01:00
|
|
|
create table phones (
|
|
|
|
id integer GENERATED BY DEFAULT AS IDENTITY,
|
|
|
|
phone_number varchar(200) not null,
|
|
|
|
number_type varchar(200) not null,
|
|
|
|
dob date,
|
|
|
|
id_person integer not null references people(id)
|
|
|
|
);
|
2019-02-21 18:11:14 +01:00
|
|
|
|
2023-10-01 15:22:43 +02:00
|
|
|
create table integers_as_booleans (
|
|
|
|
id bigint generated by default as identity primary key,
|
|
|
|
done_bool boolean not null,
|
|
|
|
done_int smallint not null
|
|
|
|
);
|
|
|
|
|
2023-11-02 17:36:19 +01:00
|
|
|
CREATE TABLE customers_with_version (
|
|
|
|
id bigint generated by default as identity NOT NULL,
|
|
|
|
code varchar(20),
|
|
|
|
description varchar(200),
|
|
|
|
city varchar(200),
|
|
|
|
note varchar(1000),
|
|
|
|
rating integer,
|
|
|
|
objversion integer
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2019-02-21 18:11:14 +01:00
|
|
|
ALTER TABLE orders ADD CONSTRAINT orders_customers_fk FOREIGN KEY (id_customer) REFERENCES customers(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
|
|
ALTER TABLE order_details ADD CONSTRAINT order_details_orders_fk FOREIGN KEY (id_order) REFERENCES orders(id) ON DELETE CASCADE ON UPDATE CASCADE;
|