1 |
|
---|
2 |
|
---|
3 | set search_path = "project";
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 | -- Delete tables if they exist
|
---|
8 | drop table if exists project.Policy;
|
---|
9 | drop table if exists project.Customer;
|
---|
10 | drop table if exists project.Pol_dog;
|
---|
11 | drop table if exists project.Payment;
|
---|
12 | drop table if exists project.Package;
|
---|
13 | drop table if exists project.Covers;
|
---|
14 | drop table if exists project.Property_pol;
|
---|
15 | drop table if exists project.Property;
|
---|
16 | drop table if exists project.Travel_pol;
|
---|
17 | drop table if exists project.Pol_osi;
|
---|
18 | drop table if exists project.Auto_pol;
|
---|
19 | drop table if exists project.Vehicle;
|
---|
20 |
|
---|
21 |
|
---|
22 | -- отстранување на шемата
|
---|
23 |
|
---|
24 | drop schema if exists project;
|
---|
25 |
|
---|
26 |
|
---|
27 | -- креирање на шемата
|
---|
28 |
|
---|
29 | create schema project;
|
---|
30 |
|
---|
31 | create table project.Package(
|
---|
32 | code integer primary key,
|
---|
33 | title varchar(255) not null,
|
---|
34 | total decimal,
|
---|
35 | valuet varchar(255)
|
---|
36 | );
|
---|
37 |
|
---|
38 | create table project.Policy(
|
---|
39 | p_id int primary key,
|
---|
40 | sdate date not null,
|
---|
41 | edate date not null,
|
---|
42 | package integer,
|
---|
43 | constraint fk_package_pol foreign key (package) references project.Package(code)
|
---|
44 | );
|
---|
45 |
|
---|
46 | create table project.Payment(
|
---|
47 | payment_num integer primary key,
|
---|
48 | policy integer,
|
---|
49 | p_date date,
|
---|
50 | p_amount integer,
|
---|
51 | constraint fk_payment_pol foreign key (policy) references project.Policy(p_id)
|
---|
52 | );
|
---|
53 |
|
---|
54 | create table project.Covers(
|
---|
55 | cov_id int primary key,
|
---|
56 | cov_amount int,
|
---|
57 | package integer,
|
---|
58 | cov_type varchar(50),
|
---|
59 | constraint fk_covers_pol foreign key (package) references project.Package(code)
|
---|
60 | );
|
---|
61 |
|
---|
62 | create table project.Customer(
|
---|
63 | c_id integer primary key,
|
---|
64 | name varchar(50),
|
---|
65 | email varchar(50) not null,
|
---|
66 | password varchar(50) not null,
|
---|
67 | type bit not null
|
---|
68 | );
|
---|
69 |
|
---|
70 | create table project.Pol_dog(
|
---|
71 | d_embg varchar(13) primary key,
|
---|
72 | c_id integer,
|
---|
73 | name varchar(255) not null,
|
---|
74 | policy integer,
|
---|
75 | surname varchar(255),
|
---|
76 | birthdate date not null,
|
---|
77 | kontakt varchar(255),
|
---|
78 | constraint fk_Profile_User foreign key (c_id) references project.Customer(c_id),
|
---|
79 | constraint fk_Pol foreign key (policy) references project.Policy(p_id)
|
---|
80 | );
|
---|
81 |
|
---|
82 | create table project.Auto_pol(
|
---|
83 | a_id integer primary key,
|
---|
84 | pol_id integer,
|
---|
85 | constraint fk_pol_vehicle foreign key (pol_id) references project.Policy(p_id)
|
---|
86 | );
|
---|
87 |
|
---|
88 | create table project.Vehicle(
|
---|
89 | v_id int primary key,
|
---|
90 | policy integer,
|
---|
91 | type varchar(255) not null,
|
---|
92 | marka varchar(255),
|
---|
93 | model varchar(255),
|
---|
94 | license_plate varchar(25) not null,
|
---|
95 | constraint fk_Pol_veh foreign key (policy) references project.Auto_pol(a_id)
|
---|
96 | );
|
---|
97 |
|
---|
98 | create table project.Travel_pol(
|
---|
99 | tr_id integer primary key,
|
---|
100 | pol_id integer,
|
---|
101 | constraint fk_pol_travel foreign key (pol_id) references project.Policy(p_id)
|
---|
102 | );
|
---|
103 |
|
---|
104 | create table project.Pol_osi(
|
---|
105 | o_embg varchar(13) primary key,
|
---|
106 | policy integer,
|
---|
107 | name varchar(255) not null,
|
---|
108 | surname varchar(255),
|
---|
109 | birthdate date not null,
|
---|
110 | kontakt varchar(255),
|
---|
111 | constraint fk_Polosi foreign key (policy) references project.Travel_pol(tr_id)
|
---|
112 | );
|
---|
113 |
|
---|
114 | create table project.Property_pol(
|
---|
115 | pr_id integer primary key,
|
---|
116 | pol_id integer,
|
---|
117 | constraint fk_PolProperty foreign key (pol_id) references project.Policy(p_id)
|
---|
118 | );
|
---|
119 |
|
---|
120 | create table project.Property(
|
---|
121 | prop_id integer primary key,
|
---|
122 | policy integer,
|
---|
123 | address varchar(255),
|
---|
124 | floor integer,
|
---|
125 | year_build date,
|
---|
126 | security bit,
|
---|
127 | constraint fk_pol_propp foreign key (policy) references project.Property_pol(pr_id)
|
---|
128 | );
|
---|
129 |
|
---|
130 |
|
---|
131 |
|
---|
132 |
|
---|
133 |
|
---|