RelationalDesign2: kreiranje_2.sql

File kreiranje_2.sql, 3.1 KB (added by 175012, 44 hours ago)
Line 
1
2drop table if exists project.Policy;
3drop table if exists project.Customer;
4drop table if exists project.Pol_dog;
5drop table if exists project.Payment;
6drop table if exists project.Package;
7drop table if exists project.Covers;
8drop table if exists project.Property_pol;
9drop table if exists project.Property;
10drop table if exists project.Travel_pol;
11drop table if exists project.Pol_osi;
12drop table if exists project.Auto_pol;
13drop table if exists project.Vehicle;
14
15create schema project;
16
17create table project.Package(
18 code integer primary key,
19 title varchar(255) not null,
20 total decimal,
21 valuet varchar(255),
22 type_pol INT
23);
24
25create table project.Policy(
26 p_id int primary key,
27 sdate date not null,
28 edate date not null,
29 package integer,
30 constraint fk_package_pol foreign key (package) references project.Package(code)
31);
32
33create table project.Payment(
34 payment_num integer primary key,
35 policy integer,
36 p_date date,
37 p_amount integer,
38 constraint fk_payment_pol foreign key (policy) references project.Policy(p_id)
39);
40
41create table project.Covers(
42 cov_id int primary key,
43 cov_amount int,
44 package integer,
45 cov_type varchar(max),
46 constraint fk_covers_pol foreign key (package) references project.Package(code)
47);
48
49create table project.Customer(
50 c_id integer primary key,
51 name varchar(50),
52 email varchar(50) not null,
53 password varchar(50) not null,
54 type bit not null
55);
56
57create table project.Pol_dog(
58 d_embg varchar(13) primary key,
59 c_id integer,
60 name varchar(255) not null,
61 policy integer,
62 surname varchar(255),
63 birthdate date not null,
64 kontakt varchar(255),
65 constraint fk_Profile_User foreign key (c_id) references project.Customer(c_id),
66 constraint fk_Pol foreign key (policy) references project.Policy(p_id)
67);
68
69create table project.Auto_pol(
70 a_id integer primary key,
71 pol_id integer,
72 constraint fk_pol_vehicle foreign key (pol_id) references project.Policy(p_id)
73);
74
75create table project.Vehicle(
76 v_id int primary key,
77 policy integer,
78 type varchar(255) not null,
79 marka varchar(255),
80 model varchar(255),
81 license_plate varchar(25) not null,
82 constraint fk_Pol_veh foreign key (policy) references project.Auto_pol(a_id)
83);
84
85create table project.Travel_pol(
86 tr_id integer primary key,
87 pol_id integer,
88 constraint fk_pol_travel foreign key (pol_id) references project.Policy(p_id)
89);
90
91create table project.Pol_osi(
92 o_embg varchar(13) primary key,
93 policy integer,
94 name varchar(255) not null,
95 surname varchar(255),
96 birthdate date not null,
97 kontakt varchar(255),
98 constraint fk_Polosi foreign key (policy) references project.Travel_pol(tr_id)
99);
100
101create table project.Property_pol(
102 pr_id integer primary key,
103 pol_id integer,
104 constraint fk_PolProperty foreign key (pol_id) references project.Policy(p_id)
105);
106
107create table project.Property(
108 prop_id integer primary key,
109 policy integer,
110 address varchar(255),
111 floor integer,
112 year_build date,
113 security bit,
114 constraint fk_pol_propp foreign key (policy) references project.Property_pol(pr_id)
115);