create table arenda id serial not null constraint arenda_pkey primary

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
create table arenda
(
id serial not null
constraint arenda_pkey
primary key,
client_id integer
)
;
create unique index arenda_id_uindex
on arenda (id)
;
create table torg_ploshad
(
id serial not null
constraint torg_ploshad_pkey
primary key,
arenda_id integer not null
constraint torg_ploshad_arenda_id_fk
references arenda,
tt_id integer not null,
begin_datetime timestamp not null,
end_datetime timestamp not null
)
;
create unique index torg_ploshad_id_uindex
on torg_ploshad (id)
;
create table tt
(
id serial not null
constraint tt_pkey
primary key,
etaj integer not null,
ploshad double precision not null,
conditioner boolean not null,
cost money not null
)
;
create unique index tt_id_uindex
on tt (id)
;
alter table torg_ploshad
add constraint torg_ploshad_tt_id_fk
foreign key (tt_id) references tt
;
create table client
(
id serial not null
constraint client_pkey
primary key,
name text not null,
rekvesit text not null,
address text not null,
telephone text not null
)
;
create unique index client_id_uindex
on client (id)
;
alter table arenda
add constraint arenda_client_id_fk
foreign key (client_id) references client
;
create table payment
(
id serial not null
constraint payment_pkey
primary key,
client_id integer not null
constraint payment_client_id_fk
references client,
date date not null,
cost money not null
)
;
create unique index payment_id_uindex
on payment (id)
;