DROP TABLE IF EXISTS main;
DROP TABLE IF EXISTS first_name;
DROP TABLE IF EXISTS last_name;
DROP TABLE IF EXISTS middle_name;
DROP TABLE IF EXISTS street;
CREATE TABLE first_name (
    first_name_id SERIAL PRIMARY KEY,
    first_name_val VARCHAR(255) NOT NULL
);
CREATE TABLE last_name (
    last_name_id SERIAL PRIMARY KEY,
    last_name_val VARCHAR(255) NOT NULL
);
CREATE TABLE middle_name (
    middle_name_id SERIAL PRIMARY KEY,
    middle_name_val VARCHAR(255) NOT NULL
);
CREATE TABLE street (
    street_id SERIAL PRIMARY KEY,
    street_val VARCHAR(255) NOT NULL
);
CREATE TABLE main (
    uid serial,
    last_name int,
    first_name int,
    middle_name int,
    street int,
    build VARCHAR(255),
    build_k VARCHAR(255),
    apartment VARCHAR(255),
    telephone VARCHAR(255) NOT NULL,
    CONSTRAINT fk_last_name FOREIGN KEY (last_name) REFERENCES last_name(last_name_id),
    CONSTRAINT fk_first_name FOREIGN KEY (first_name) REFERENCES first_name(first_name_id),
    CONSTRAINT fk_middle_name FOREIGN KEY (middle_name) REFERENCES middle_name(middle_name_id),
    CONSTRAINT fk_street FOREIGN KEY (street) REFERENCES street(street_id),
    PRIMARY KEY (uid)
);