-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.sql
82 lines (74 loc) · 2.13 KB
/
create.sql
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
set client_encoding='utf-8';
create table klient(
id serial PRIMARY KEY,
imie_kl varchar(15) NOT NULL,
nazwisko_kl varchar(25) NOT NULL,
nr_tel int NOT NULL,
adres varchar(40)
);
create table uslugi(
id serial PRIMARY KEY,
nazwa_uslugi varchar(40) NOT NULL UNIQUE,
cena_uslugi int NOT NULL
);
create table czesci(
id serial PRIMARY KEY,
nazwa_czesci varchar(40) NOT NULL UNIQUE,
cena int NOT NULL,
ilosc int
);
create table pracownik(
id serial PRIMARY KEY,
imie_prac varchar(20) NOT NULL,
nazwisko_prac varchar(25) NOT NULL,
stanowisko varchar(15)
);
create table sprzet(
id serial PRIMARY KEY,
data_przyj date not null,
data_zakon date,
nr_seryjny varchar(20),
kategoria varchar(20),
model varchar(15),
id_klient int NOT NULL,
id_pracownik int,
constraint id_klient_fk FOREIGN KEY(id_klient)
references klient(id)
ON DELETE CASCADE ON UPDATE CASCADE,
constraint id_pracownik_fk FOREIGN KEY(id_pracownik)
references pracownik(id)
ON DELETE SET NULL ON UPDATE CASCADE
);
create table wykonane_uslugi(
id_uslugi int NOT NULL,
id_sprzet int NOT NULL,
constraint id_uslugi_fk FOREIGN KEY(id_uslugi)
references uslugi(id)
ON DELETE CASCADE ON UPDATE CASCADE,
constraint id_sprzet_fk FOREIGN KEY(id_sprzet)
references sprzet(id)
ON DELETE CASCADE ON UPDATE CASCADE
);
create table uzyte_czesci(
id_czesci int NOT NULL,
id_sprzet int NOT NULL,
constraint id_czesci_fk FOREIGN KEY(id_czesci)
references czesci(id)
ON DELETE CASCADE ON UPDATE CASCADE,
constraint id_sprzet_fk FOREIGN KEY(id_sprzet)
references sprzet(id)
ON DELETE CASCADE ON UPDATE CASCADE
);
create table faktura(
id serial PRIMARY KEY,
nr_faktury varchar(12),
id_pracownik int,
id_sprzet int NOT NULL UNIQUE,
data_wyst date NOT NULL,
constraint id_pracownik_fk FOREIGN KEY(id_pracownik)
references pracownik(id)
ON DELETE SET NULL ON UPDATE CASCADE,
constraint id_sprzet_fk FOREIGN KEY(id_sprzet)
references sprzet(id)
ON DELETE CASCADE ON UPDATE CASCADE
);