RelationalDesign: kreiranje.sql

File kreiranje.sql, 5.4 KB (added by 193041, 2 years ago)
Line 
1create table project.admini(
2 id_admin integer primary key,
3 ime varchar(50) not null,
4 prezime varchar(50) not null,
5 email varchar(50) not null,
6 password varchar(300) not null
7);
8
9create table project.nastavnici(
10 id_nastavnik serial primary key,
11 ime varchar(50) not null,
12 prezime varchar(50) not null,
13 opis varchar(500) not null,
14 email varchar(50) not null,
15 password varchar(300) not null,
16 telefonski_broj varchar(15),
17 enabled bool,
18 id_admin integer not null,
19 constraint fk_admin foreign key(id_admin) references project.admini(id_admin)
20 on delete cascade on update cascade
21);
22
23create table project.kvalifikacii (
24 id_kvalifikacija serial primary key,
25 dokument text,
26 id_nastavnik integer not null,
27 id_admin integer not null,
28 constraint fk_admin foreign key(id_admin) references project.admini(id_admin)
29 on delete cascade on update cascade,
30 constraint fk_nastavnik foreign key (id_nastavnik) references project.nastavnici(id_nastavnik)
31 on delete cascade on update cascade
32);
33
34create table project.predmeti (
35 id_predmet serial primary key,
36 ime varchar(100) not null,
37 id_admin integer not null,
38 constraint fk_admin foreign key(id_admin) references project.admini(id_admin)
39 on delete cascade on update cascade
40);
41
42create table project.ucenici (
43 id_ucenik serial primary key,
44 opis varchar(500),
45 ime varchar(50) not null,
46 prezime varchar(50) not null,
47 email varchar(50) not null,
48 password varchar(300) not null,
49 telefonski_broj varchar(15)
50);
51
52create table project.casovi (
53 id_cas serial primary key,
54 vreme_pocetok timestamp,
55 tema varchar(100) not null,
56 id_nastavnik integer,
57 id_predmet integer,
58 constraint fk_nastavnik foreign key (id_nastavnik) references project.nastavnici(id_nastavnik)
59 on delete cascade on update cascade,
60 constraint fk_predmet foreign key (id_predmet) references project.predmeti(id_predmet)
61 on delete cascade on update cascade
62);
63
64create table project.zainteresiran_za (
65 id_predmet integer,
66 id_ucenik integer,
67 datum date,
68 constraint pk_zainteresiran_za primary key (id_ucenik,id_predmet),
69 constraint fk_predmet foreign key (id_predmet) references project.predmeti(id_predmet)
70 on delete cascade on update cascade,
71 constraint fk_ucenik foreign key (id_ucenik) references project.ucenici(id_ucenik)
72 on delete cascade on update cascade
73);
74
75create table project.domasni_zadaci (
76 id_domasno serial primary key,
77 opis varchar(500),
78 id_nastavnik integer not null,
79 id_cas integer not null,
80 constraint fk_cas foreign key (id_cas) references project.casovi(id_cas)
81 on delete cascade on update cascade,
82 constraint fk_nastavnik foreign key (id_nastavnik) references project.nastavnici(id_nastavnik)
83 on delete cascade on update cascade
84);
85
86
87create table project.ucenici_domasni (
88 id_ucenik integer,
89 id_domasno integer,
90 dali_zavrsena bool,
91 constraint pk_ucenik_domasno primary key (id_ucenik,id_domasno),
92 constraint fk_domasno foreign key (id_domasno) references project.domasni_zadaci(id_domasno)
93 on delete cascade on update cascade,
94 constraint fk_ucenik foreign key (id_ucenik) references project.ucenici(id_ucenik)
95 on delete cascade on update cascade
96);
97
98create table project.plakjanja (
99 id_plakjanja serial primary key,
100 iznos integer not null,
101 id_nastavnik integer not null,
102 constraint fk_nastavnik foreign key (id_nastavnik) references project.nastavnici(id_nastavnik)
103);
104
105create table project.slusanje (
106 id_cas integer,
107 id_slusanje integer,
108 id_plakjanja integer,
109 id_ucenik integer,
110 plateno boolean,
111 constraint pk_slusanje primary key (id_cas, id_slusanje),
112 constraint fk_cas foreign key(id_cas) references project.casovi(id_cas)
113 on delete cascade on update cascade,
114 constraint fk_plakjanje foreign key (id_plakjanja) references project.plakjanja(id_plakjanja)
115 on delete cascade on update cascade,
116 constraint fk_ucenik foreign key (id_ucenik) references project.ucenici(id_ucenik)
117 on delete cascade on update cascade
118);
119
120
121create table project.predava_predmet (
122 id_nastavnik integer,
123 id_predmet integer,
124 opis varchar(500) not null,
125
126 constraint pk_predava_predmet primary key (id_nastavnik, id_predmet),
127 constraint fk_nastavnik foreign key (id_nastavnik) references project.nastavnici(id_nastavnik)
128 on delete cascade on update cascade,
129 constraint fk_predmet foreign key (id_predmet) references project.predmeti(id_predmet)
130 on delete cascade on update cascade
131);
132
133create table project.predava_na (
134 id_nastavnik integer,
135 id_ucenik integer,
136 cena_po_cas integer not null,
137 broj_casovi_po_dogovor integer not null,
138 rejting float,
139 komentar varchar(500),
140 hasrated boolean,
141 constraint pk_predava_na primary key (id_nastavnik, id_ucenik),
142 constraint fk_nastavnik foreign key (id_nastavnik) references project.nastavnici(id_nastavnik)
143 on delete cascade on update cascade,
144 constraint fk_ucenik foreign key (id_ucenik) references project.ucenici(id_ucenik)
145 on delete cascade on update cascade
146);
147
148-- brisenje tabeli
149drop table project.predava_na ;
150drop table project.predava_predmet ;
151drop table project.slusanje ;
152drop table project.plakjanja ;
153drop table project.ucenici_domasni ;
154drop table project.zainteresiran_za ;
155drop table project.ucenici ;
156drop table project.domasni_zadaci ;
157drop table project.casovi ;
158drop table project.kvalifikacii ;
159drop table project.nastavnici ;
160drop table project.predmeti ;
161drop table project.admini ;
162
163