Advertisement
mankanos

Banka

Feb 16th, 2021
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. create table grad
  2. (
  3. id_grad integer not null
  4. constraint pk_grad
  5. primary key,
  6. ime_grad varchar(100) not null
  7. );
  8.  
  9. alter table grad owner to postgres;
  10.  
  11. grant insert, select, update on grad to student;
  12.  
  13. create table filijala
  14. (
  15. id_filijala integer not null
  16. constraint pk_filijala
  17. primary key,
  18. adresa_filijala varchar(255) not null,
  19. id_grad integer not null
  20. constraint fk_filijala_e_locirana_vo_grad
  21. references grad
  22. );
  23.  
  24. alter table filijala owner to postgres;
  25.  
  26. grant insert, select, update on filijala to student;
  27.  
  28. create table chovek
  29. (
  30. embg char(13) not null
  31. constraint pk_chovek
  32. primary key,
  33. ime varchar(100) not null,
  34. prezime varchar(100) not null
  35. );
  36.  
  37. alter table chovek owner to postgres;
  38.  
  39. grant insert, select, update on chovek to student;
  40.  
  41. create table klient
  42. (
  43. embg_klient char(13) not null
  44. constraint pk_klient
  45. primary key
  46. constraint fk_klient_embg_chovek
  47. references chovek,
  48. adresa_ziveenje varchar(150),
  49. id_grad integer not null
  50. constraint fk_klient_grad_zhivee
  51. references grad
  52. );
  53.  
  54. alter table klient owner to postgres;
  55.  
  56. create table smetka
  57. (
  58. broj_smetka integer not null
  59. constraint pk_smetka
  60. primary key,
  61. valuta char(3) not null,
  62. saldo double precision not null,
  63. dozvolen_minus double precision,
  64. embg_klient char(13) not null
  65. constraint fk_smetka_klient
  66. references klient
  67. );
  68.  
  69. alter table smetka owner to postgres;
  70.  
  71. grant insert, select, update on smetka to student;
  72.  
  73. create table transakcija
  74. (
  75. broj_transakcija integer not null
  76. constraint pk_transakcija
  77. primary key,
  78. vreme_izvrsuvanje timestamp not null,
  79. valuta char(3) not null,
  80. suma double precision not null,
  81. broj_smetka_uplata integer not null
  82. constraint fk_transakcija_smetka_uplata
  83. references smetka,
  84. broj_smetka_isplata integer not null
  85. constraint fk_transakcija_smetka_isplata
  86. references smetka
  87. );
  88.  
  89. alter table transakcija owner to postgres;
  90.  
  91. grant insert, select, update on transakcija to student;
  92.  
  93. create table kredit
  94. (
  95. id_kredit integer not null,
  96. broj_smetka integer not null
  97. constraint fk_kredit_kon_smetka
  98. references smetka,
  99. datum_otvoranje date not null,
  100. rata double precision not null,
  101. constraint pk_kredit
  102. primary key (id_kredit, broj_smetka)
  103. );
  104.  
  105. alter table kredit owner to postgres;
  106.  
  107. grant insert, select, update on kredit to student;
  108.  
  109. create table telefonski_broj
  110. (
  111. embg_klient char(13) not null
  112. constraint fk_telefonski_broj_embg
  113. references klient,
  114. telefonski_broj varchar(15) not null,
  115. constraint pk_telefon
  116. primary key (embg_klient, telefonski_broj)
  117. );
  118.  
  119. alter table telefonski_broj owner to postgres;
  120.  
  121. grant insert, select, update on telefonski_broj to student;
  122.  
  123. grant insert, select, update on klient to student;
  124.  
  125. create table vraboten
  126. (
  127. embg char(13) not null
  128. constraint pk_vraboten
  129. primary key,
  130. datum_vrabotuvanje date not null,
  131. id_dogovor integer not null,
  132. id_filijala integer
  133. constraint fk_vraboten_vo_filijala
  134. references filijala,
  135. rabotno_mesto varchar(100),
  136. embg_shef char(13) not null
  137. constraint fk_shef_vraboten
  138. references vraboten
  139. );
  140.  
  141. alter table vraboten owner to postgres;
  142.  
  143. grant insert, select, update on vraboten to student;
  144.  
  145. create table ovlasten
  146. (
  147. embg char(13) not null
  148. constraint fk_ovlasten_klient
  149. references klient,
  150. broj_smetka integer not null
  151. constraint fk_ovlastuvanje_smetka
  152. references smetka,
  153. ovlasten_od date not null,
  154. ovlasten_do date,
  155. constraint pk_ovlasten
  156. primary key (embg, broj_smetka)
  157. );
  158.  
  159. alter table ovlasten owner to postgres;
  160.  
  161. grant insert, select, update on ovlasten to student;
  162.  
  163. create table otvorena_vo
  164. (
  165. broj_smetka integer not null
  166. constraint fk_otvorena_smetka
  167. references smetka,
  168. id_filijala integer not null
  169. constraint fk_smetka_otvorena_vo_filijala
  170. references filijala,
  171. embg_vraboten char(13) not null
  172. constraint fk_smetka_otvorena_od
  173. references vraboten,
  174. constraint pk_otvorena_vo
  175. primary key (broj_smetka, id_filijala, embg_vraboten)
  176. );
  177.  
  178. alter table otvorena_vo owner to postgres;
  179.  
  180. grant insert, select, update on otvorena_vo to student;
  181.  
  182. create view mesecni_transakcii(ime_uplakjach, prezime_uplakjach, embg_uplakjach, ime_isplaten, prezime_isplaten, embg_isplaten, vreme_izvrsuvanje, suma, valuta) as
  183. SELECT chu.ime AS ime_uplakjach,
  184. chu.prezime AS prezime_uplakjach,
  185. chu.embg AS embg_uplakjach,
  186. chi.ime AS ime_isplaten,
  187. chi.prezime AS prezime_isplaten,
  188. chi.embg AS embg_isplaten,
  189. t.vreme_izvrsuvanje,
  190. t.suma,
  191. t.valuta
  192. FROM banka.transakcija t
  193. JOIN banka.smetka su ON t.broj_smetka_uplata = su.broj_smetka
  194. JOIN banka.klient ku ON su.embg_klient = ku.embg_klient
  195. JOIN banka.chovek chu ON ku.embg_klient = chu.embg
  196. JOIN banka.smetka si ON t.broj_smetka_isplata = si.broj_smetka
  197. JOIN banka.klient ki ON si.embg_klient = ki.embg_klient
  198. JOIN banka.chovek chi ON ki.embg_klient = chi.embg
  199. WHERE date_part('month'::text, t.vreme_izvrsuvanje) = date_part('month'::text, now())
  200. AND date_part('year'::text, t.vreme_izvrsuvanje) = date_part('year'::text, now())
  201. ORDER BY t.vreme_izvrsuvanje;
  202.  
  203. alter table mesecni_transakcii owner to postgres;
  204.  
  205.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement