RelationalDesign2: kreiranje_1.sql

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