RelationalDesign: kreiranje.sql

File kreiranje.sql, 2.0 KB (added by 201156, 9 months ago)
Line 
1--Create Tables
2CREATE TABLE Firma (
3 FirmaID SERIAL PRIMARY KEY,
4 Adresa VARCHAR(255),
5 Broj VARCHAR(255)
6)
7
8CREATE TABLE Artikl (
9 ArtiklID SERIAL PRIMARY KEY,
10 Cena DECIMAL,
11 EdMera VARCHAR(255),
12 StapkaDDV DECIMAL,
13 Zaliha INT
14)
15
16CREATE TABLE Naracka (
17 NarackaID SERIAL PRIMARY KEY,
18 Kolicina INT,
19 Datum DATE,
20 Opis TEXT
21)
22
23CREATE TABLE IzrabotkaPlan (
24 DatumStart DATE,
25 DatumEnd DATE
26)
27
28CREATE TABLE Faktura (
29 FakturaID SERIAL PRIMARY KEY,
30 Datum DATE,
31 Iznos DECIMAL,
32 Broj VARCHAR(255)
33)
34
35
36CREATE 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
44CREATE 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
52CREATE 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
60CREATE 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
68CREATE 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
77DROP TABLE IF EXISTS Faktura_Naracka;
78DROP TABLE IF EXISTS Faktura_Firma;
79DROP TABLE IF EXISTS Naracka_Firma;
80DROP TABLE IF EXISTS Naracka_IzrabotkaPlan;
81DROP TABLE IF EXISTS Naracka_Artikl;
82DROP TABLE IF EXISTS Faktura;
83DROP TABLE IF EXISTS IzrabotkaPlan;
84DROP TABLE IF EXISTS Naracka;
85DROP TABLE IF EXISTS Artikl;
86DROP TABLE IF EXISTS Firma;