Paste this into a new question or an answer at dba.stackexchange.com:
<!-- --> > create table meno_rusis( > id INTEGER not null check (id > 100), > pavadinimas VARCHAR (100) not null, > primary key(id) > ); > > create table autorius( > id INTEGER not null check (id > 1000000), > vardas VARCHAR (40) not null, > pavarde VARCHAR (55) not null, > gimimo_metai DATE, > primary key(id) > ); > > create table klientas( > id INTEGER not null check (id > 1000000), > vardas VARCHAR (40), > pavarde VARCHAR (55), > primary key(id) > ); > > <pre> > </pre> <!-- --> > create table kurinys( > id INTEGER not null check (id > 10000), > pavadinimas VARCHAR (55) not null, > metai INT, > meno_rusies_id INTEGER not null check (meno_rusies_id > 100), > autoriaus_id INTEGER not null check (autoriaus_id > 1000000), > kliento_id INTEGER not null check (kliento_id > 1000000), > ilgis_cm DECIMAL (100,2), > plotis_cm DECIMAL (100,2), > kaina DECIMAL (100,2), > primary key (id), > foreign key (meno_rusies_id) > REFERENCES meno_rusis on delete cascade on update restrict, > foreign key (autoriaus_id) > REFERENCES autorius on delete cascade on update restrict, > foreign key (kliento_id) > REFERENCES klientas on delete cascade on update restrict > ); > > <pre> > </pre> *db<>fiddle [here](https://dbfiddle.uk/?rdbms=postgres_9.5&fiddle=d8fcb531295ecfddd6e20b0fb961c848)*
back to fiddle