RelationalDesign: kreiranje.sql

File kreiranje.sql, 2.7 KB (added by 201144, 2 years ago)
Line 
1CREATE TABLE city(
2 cityname varchar(50) primary key
3);
4
5CREATE TABLE faculty(
6 facultyid serial primary key,
7 facultyname varchar(255) not null,
8 cityname varchar(255) references city(cityname)
9);
10
11CREATE TABLE building(
12 buildingid serial primary key,
13 cityname varchar(255) references city(cityname),
14 building_adress varchar(255)
15);
16
17
18CREATE TABLE appuser(
19 userid serial unique not null,
20 prezime varchar(13) not null,
21 ime varchar(200) not null,
22 pass varchar(200) not null,
23 phone_number varchar(30) not null,
24 city_of_residency varchar(50),
25 datumragj date
26);
27
28CREATE TABLE administrator(
29 adminid integer primary key references appuser(userid),
30 adminrole varchar(255) not null
31);
32
33CREATE TABLE apartment_owner(
34 ownerid integer primary key references appuser(userid)
35);
36
37CREATE TABLE student(
38 studentid integer not null primary key references appuser(userid),
39 facultyid integer not null references faculty(facultyid),
40 age integer,
41 gender varchar(255)
42);
43
44CREATE TABLE apartment(
45 apartmentid serial primary key,
46 buildingid integer references building(buildingid) not null,
47 ownerid integer references apartment_owner(ownerid) not null,
48 apartment_adress varchar(255) not null,
49 apartment_size varchar(255) not null
50
51);
52
53
54
55
56CREATE TABLE apartment_agreement(
57 apartment_agreementid serial primary key,
58 apartmentid integer not null references apartment(apartmentid),
59 ownerid integer not null references apartment_owner(ownerid),
60 date_signed date not null,
61 date_expires date not null,
62 apartment_rent integer not null
63);
64
65
66
67
68CREATE TABLE post(
69 postid serial primary key,
70 cityname varchar(255) references city(cityname),
71 number_of_roommates integer not null,
72 price integer not null,
73 date_posted date not null,
74 description varchar(255)
75);
76
77
78
79
80CREATE TABLE student_post(
81 student_postid integer primary key references post(postid),
82 studentid integer not null references student(studentid)
83);
84
85CREATE TABLE owner_post(
86 owner_postid integer not null primary key references post(postid),
87 apartmentid integer not null references apartment(apartmentid),
88 ownerid integer not null references apartment_owner(ownerid)
89);
90
91CREATE TABLE apartment_photos(
92 postid integer references owner_post(owner_postid) primary key,
93 photosurl varchar(1000)
94);
95
96CREATE TABLE moderates_posts_for(
97 cityname varchar(255) not null references city(cityname),
98 adminid integer not null references administrator(adminid),
99 primary key(cityname,adminid)
100);
101
102CREATE TABLE student_signs(
103 studentid integer not null references student(studentid),
104 agreementid integer not null references apartment_agreement(apartment_agreementid),
105 primary key(studentid,agreementid)
106);