1 | --Create Tables
|
---|
2 | CREATE TABLE Firma (
|
---|
3 | FirmaID SERIAL PRIMARY KEY,
|
---|
4 | Adresa VARCHAR(255),
|
---|
5 | Broj VARCHAR(255)
|
---|
6 | )
|
---|
7 |
|
---|
8 | CREATE TABLE Artikl (
|
---|
9 | ArtiklID SERIAL PRIMARY KEY,
|
---|
10 | Cena DECIMAL,
|
---|
11 | EdMera VARCHAR(255),
|
---|
12 | StapkaDDV DECIMAL,
|
---|
13 | Zaliha INT
|
---|
14 | )
|
---|
15 |
|
---|
16 | CREATE TABLE Naracka (
|
---|
17 | NarackaID SERIAL PRIMARY KEY,
|
---|
18 | Kolicina INT,
|
---|
19 | Datum DATE,
|
---|
20 | Opis TEXT
|
---|
21 | )
|
---|
22 |
|
---|
23 | CREATE TABLE IzrabotkaPlan (
|
---|
24 | DatumStart DATE,
|
---|
25 | DatumEnd DATE
|
---|
26 | )
|
---|
27 |
|
---|
28 | CREATE TABLE Faktura (
|
---|
29 | FakturaID SERIAL PRIMARY KEY,
|
---|
30 | Datum DATE,
|
---|
31 | Iznos DECIMAL,
|
---|
32 | Broj VARCHAR(255)
|
---|
33 | )
|
---|
34 |
|
---|
35 |
|
---|
36 | CREATE TABLE Naracka_Artikl (
|
---|
37 | NarackaID INT,
|
---|
38 | ArtiklID INT,
|
---|
39 | FOREIGN KEY (NarackaID) REFERENCES Naracka(NarackaID),
|
---|
40 | FOREIGN KEY (ArtiklID) REFERENCES Artikl(ArtiklID),
|
---|
41 | PRIMARY KEY (NarackaID, ArtiklID)
|
---|
42 | )
|
---|
43 |
|
---|
44 | CREATE TABLE Naracka_IzrabotkaPlan (
|
---|
45 | NarackaID INT,
|
---|
46 | DatumStart DATE,
|
---|
47 | DatumEnd DATE,
|
---|
48 | FOREIGN KEY (NarackaID) REFERENCES Naracka(NarackaID),
|
---|
49 | PRIMARY KEY (NarackaID, DatumStart, DatumEnd)
|
---|
50 | )
|
---|
51 |
|
---|
52 | CREATE TABLE Naracka_Firma (
|
---|
53 | NarackaID INT,
|
---|
54 | FirmaID INT,
|
---|
55 | FOREIGN KEY (NarackaID) REFERENCES Naracka(NarackaID),
|
---|
56 | FOREIGN KEY (FirmaID) REFERENCES Firma(FirmaID),
|
---|
57 | PRIMARY KEY (NarackaID, FirmaID)
|
---|
58 | )
|
---|
59 |
|
---|
60 | CREATE TABLE Faktura_Firma (
|
---|
61 | FakturaID INT,
|
---|
62 | FirmaID INT,
|
---|
63 | FOREIGN KEY (FakturaID) REFERENCES Faktura(FakturaID),
|
---|
64 | FOREIGN KEY (FirmaID) REFERENCES Firma(FirmaID),
|
---|
65 | PRIMARY KEY (FakturaID, FirmaID)
|
---|
66 | )
|
---|
67 |
|
---|
68 | CREATE TABLE Faktura_Naracka (
|
---|
69 | FakturaID INT,
|
---|
70 | NarackaID INT,
|
---|
71 | FOREIGN KEY (FakturaID) REFERENCES Faktura(FakturaID),
|
---|
72 | FOREIGN KEY (NarackaID) REFERENCES Naracka(NarackaID),
|
---|
73 | PRIMARY KEY (FakturaID, NarackaID)
|
---|
74 | )
|
---|
75 |
|
---|
76 | --delete Tables
|
---|
77 | DROP TABLE IF EXISTS Faktura_Naracka;
|
---|
78 | DROP TABLE IF EXISTS Faktura_Firma;
|
---|
79 | DROP TABLE IF EXISTS Naracka_Firma;
|
---|
80 | DROP TABLE IF EXISTS Naracka_IzrabotkaPlan;
|
---|
81 | DROP TABLE IF EXISTS Naracka_Artikl;
|
---|
82 | DROP TABLE IF EXISTS Faktura;
|
---|
83 | DROP TABLE IF EXISTS IzrabotkaPlan;
|
---|
84 | DROP TABLE IF EXISTS Naracka;
|
---|
85 | DROP TABLE IF EXISTS Artikl;
|
---|
86 | DROP TABLE IF EXISTS Firma;
|
---|