ddlScript: ddlScript.sql

File ddlScript.sql, 5.0 KB (added by 223270, 5 days ago)
Line 
1DROP DATABASE IF EXISTS ddl_script_travel_sage;
2CREATE DATABASE ddl_script_travel_sage;
3USE ddl_script_travel_sage;
4
5DROP TABLE IF EXISTS DESTINACII CASCADE;
6DROP TABLE IF EXISTS KORISNICI CASCADE;
7DROP TABLE IF EXISTS STANDARD CASCADE;
8DROP TABLE IF EXISTS PREMIUM CASCADE;
9DROP TABLE IF EXISTS RECENZII CASCADE;
10DROP TABLE IF EXISTS METEROLOSHKASOSTOJBA CASCADE;
11DROP TABLE IF EXISTS PAKETI CASCADE;
12DROP TABLE IF EXISTS AKTIVNOSTI CASCADE;
13DROP TABLE IF EXISTS REZERVACII CASCADE;
14DROP TABLE IF EXISTS PREFERENCI CASCADE;
15DROP TABLE IF EXISTS NASTANI CASCADE;
16DROP TABLE IF EXISTS TAGOVI CASCADE;
17
18CREATE TABLE TAGOVI (
19 idTag INT AUTO_INCREMENT PRIMARY KEY,
20 tagOznaka VARCHAR(255) NOT NULL
21);
22
23CREATE TABLE DESTINACII (
24 idDest INT AUTO_INCREMENT PRIMARY KEY,
25 imeLokacija VARCHAR(255) NOT NULL,
26 opisLokacija VARCHAR(255),
27 tipoviMesta VARCHAR(255) NOT NULL,
28 preporachanaSezona VARCHAR(255) NOT NULL,
29 prosechnaTemp DECIMAL(5, 2),
30 -- geoLokacija GEOGRAPHY(Point, 4326) KOORDINATI
31 lat DECIMAL(9, 6),
32 lon DECIMAL(9, 6),
33 drzhava VARCHAR(255),
34 popularnost INT,
35 ime VARCHAR(255) NOT NULL,
36 opis VARCHAR(255) NOT NULL,
37 idTag INT,
38 CONSTRAINT fk_tag_dest FOREIGN KEY (idTag) REFERENCES TAGOVI(idTag)
39);
40
41CREATE TABLE METEROLOSHKASOSTOJBA (
42 idMeteo INT AUTO_INCREMENT PRIMARY KEY,
43 momentTemp DECIMAL(5, 2),
44 sostojbaVreme VARCHAR(255) NOT NULL,
45 predupreduvanja VARCHAR(255) NOT NULL,
46 vlazhnost DECIMAL(5, 2),
47 veter DECIMAL(5, 2),
48 mesec INT,
49 idDest INT,
50 CONSTRAINT fk_dest_meteo FOREIGN KEY (idDest) REFERENCES DESTINACII(idDest)
51);
52
53CREATE TABLE AKTIVNOSTI (
54 idAktivnost INT AUTO_INCREMENT PRIMARY KEY,
55 imeAktivnost VARCHAR(255) NOT NULL,
56 informacii VARCHAR(255),
57 kategorija VARCHAR(255) NOT NULL,
58 iznos INT,
59 idDest INT,
60 CONSTRAINT fk_dest_aktivnost FOREIGN KEY (idDest) REFERENCES DESTINACII(idDest)
61);
62
63CREATE TABLE KORISNICI (
64 idKorisnik INT AUTO_INCREMENT PRIMARY KEY,
65 ime VARCHAR(255) NOT NULL,
66 prezime VARCHAR(255) NOT NULL,
67 ePoshta VARCHAR(255) NOT NULL UNIQUE,
68 telBr VARCHAR(255) NOT NULL,
69 datumRagjanje DATE,
70 idDest INT,
71 CONSTRAINT fk_dest_korisnik FOREIGN KEY (idDest) REFERENCES DESTINACII(idDest)
72);
73
74CREATE TABLE STANDARD (
75 idKorisnik INT,
76 ime VARCHAR(255) NOT NULL,
77 prezime VARCHAR(255) NOT NULL,
78 ePoshta VARCHAR(255) NOT NULL UNIQUE,
79 telBr VARCHAR(255) NOT NULL,
80 datumRagjanje DATE,
81 CONSTRAINT fk_korisnik_standard FOREIGN KEY (idKorisnik) REFERENCES KORISNICI(idKorisnik)
82);
83
84CREATE TABLE PREMIUM (
85 idKorisnik INT,
86 ime VARCHAR(255) NOT NULL,
87 prezime VARCHAR(255) NOT NULL,
88 ePoshta VARCHAR(255) NOT NULL UNIQUE,
89 telBr VARCHAR(255) NOT NULL,
90 datumRagjanje DATE,
91 datumKreiranje DATE,
92 popust DECIMAL(5, 2),
93 CONSTRAINT fk_korisnik_premium FOREIGN KEY (idKorisnik) REFERENCES KORISNICI(idKorisnik)
94);
95
96CREATE TABLE REZERVACII (
97 idRezervacija INT AUTO_INCREMENT PRIMARY KEY,
98 vremenskaTochka DATE NOT NULL,
99 vkupnaCena INT NOT NULL,
100 idAktivnost INT,
101 idKorisnik INT,
102 idMeteo INT,
103 CONSTRAINT fk_aktivnost_rezervacija FOREIGN KEY (idAktivnost) REFERENCES AKTIVNOSTI(idAktivnost),
104 CONSTRAINT fk_korisnik_rezervacija FOREIGN KEY (idKorisnik) REFERENCES KORISNICI(idKorisnik),
105 CONSTRAINT fk_meteo_rezervacija FOREIGN KEY (idMeteo) REFERENCES METEROLOSHKASOSTOJBA(idMeteo)
106);
107
108CREATE TABLE RECENZII (
109 idRecenzija INT AUTO_INCREMENT PRIMARY KEY,
110 korisnichkoIme VARCHAR(255) NOT NULL,
111 kvalitet INT NOT NULL,
112 zabeleshka VARCHAR(255),
113 datumRecenzija DATE,
114 brGlasovi INT,
115 idDest INT,
116 idKorisnik INT,
117 idRezervacija INT,
118 CONSTRAINT fk_dest_recenzija FOREIGN KEY (idDest) REFERENCES DESTINACII(idDest),
119 CONSTRAINT fk_korisnik_recenzija FOREIGN KEY (idKorisnik) REFERENCES KORISNICI(idKorisnik),
120 CONSTRAINT fk_rezervacija_recenzija FOREIGN KEY (idRezervacija) REFERENCES REZERVACII(idRezervacija)
121);
122
123CREATE TABLE PAKETI (
124 idPaket INT AUTO_INCREMENT PRIMARY KEY,
125 imePaket VARCHAR(255) NOT NULL,
126 cena INT NOT NULL,
127 pochetok DATETIME NOT NULL,
128 kraj DATETIME NOT NULL,
129 idDest INT,
130 idAktivnost INT,
131 idRezervacija INT,
132 CONSTRAINT fk_dest_paket FOREIGN KEY (idDest) REFERENCES DESTINACII(idDest),
133 CONSTRAINT fk_aktivnost_paket FOREIGN KEY (idAktivnost) REFERENCES AKTIVNOSTI(idAktivnost),
134 CONSTRAINT fk_rezervacija_paket FOREIGN KEY (idRezervacija) REFERENCES REZERVACII(idRezervacija)
135);
136
137CREATE TABLE PREFERENCI (
138 idPreferenca INT AUTO_INCREMENT PRIMARY KEY,
139 tipPreferenca VARCHAR(255) NOT NULL,
140 prioritet INT,
141 idKorisnik INT,
142 CONSTRAINT fk_korisnik_preferenca FOREIGN KEY (idKorisnik) REFERENCES KORISNICI(idKorisnik)
143);
144
145CREATE TABLE NASTANI (
146 idNastan INT AUTO_INCREMENT PRIMARY KEY,
147 naziv VARCHAR(255) NOT NULL,
148 vidovi VARCHAR(255) NOT NULL,
149 pochetenDatum DATE,
150 kraenDatum DATE,
151 detali VARCHAR(255),
152 idDest INT,
153 CONSTRAINT fk_dest_nastan FOREIGN KEY (idDest) REFERENCES DESTINACII(idDest)
154);
155
156ALTER TABLE DESTINACII ADD FOREIGN KEY (idTag) REFERENCES TAGOVI(idTag);
157