RelationalDesign2: kreiranje.sql

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