KEY?
CREATE SCHEMA employees;
SET search_path = employees;
CREATE TYPE employee_gender AS ENUM ('M','F');
CREATE TABLE department
(
id character(4) NOT NULL,
dept_name character varying(40) NOT NULL
);
CREATE TABLE employee
(
id bigint NOT NULL,
birth_date date NOT NULL,
first_name character varying(14) NOT NULL,
last_name character varying(16) NOT NULL,
gender employee_gender NOT NULL,
hire_date date NOT NULL
);
CREATE SEQUENCE id_employee_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE id_employee_seq OWNED BY employee.id;
CREATE TABLE department_employee
(
employee_id bigint NOT NULL,
department_id character(4) NOT NULL,
from_date date NOT NULL,
to_date date NOT NULL
);
CREATE TABLE department_manager
(
employee_id bigint NOT NULL,
department_id character(4) NOT NULL,
from_date date NOT NULL,
to_date date NOT NULL
);
CREATE TABLE salary
(
employee_id bigint NOT NULL,
amount bigint NOT NULL,
from_date date NOT NULL,
to_date date NOT NULL
);
CREATE TABLE title
(
employee_id bigint NOT NULL,
title character varying(50) NOT NULL,
from_date date NOT NULL,
to_date date
);
ALTER TABLE ONLY employee
ALTER COLUMN id SET DEFAULT nextval('id_employee_seq'::regclass);
тут есть https://metanit.com/sql/postgresql/2.5.php
Обсуждают сегодня