RelationalDesign: kireiranjenew.sql

File kireiranjenew.sql, 2.8 KB (added by 201144, 16 months ago)
Line 
1CREATE TABLE city (
2 CityID serial primary key,
3 CityName varchar(50) not null
4);
5
6CREATE TABLE faculty (
7 FacultyID serial primary key,
8 FacultyName varchar(255) not null,
9 CityID integer references city(CityID)
10);
11
12CREATE TABLE building (
13 BuildingID serial primary key,
14 CityID integer references city(CityID),
15 BuildingAddress varchar(255)
16);
17
18CREATE TABLE appuser(
19 userid serial unique,
20 username varchar(30) not null,
21 password varchar(255),
22 email_address varchar(255),
23 ime varchar(255),
24 prezime varchar(255),
25 phone_number varchar(255)
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 ApartmentFloorAndRoomNumber varchar(255) not null,
49 ApartmentSize varchar(255) not null
50);
51
52CREATE TABLE apartment_agreement (
53 AgreementID serial primary key,
54 ApartmentID integer not null references apartment(ApartmentID),
55 OwnerID integer not null references apartment_owner(OwnerID),
56 DateSigned date not null,
57 DateExpires date not null,
58 ApartmentRent integer not null
59);
60
61CREATE TABLE post (
62 PostID serial primary key,
63 CityID integer references city(CityID),
64 NumberOfRoommates integer not null,
65 Price integer not null,
66 DatePosted date not null,
67 Description varchar(255)
68);
69
70CREATE TABLE student_post (
71 StudentPostID integer primary key references post(PostID),
72 StudentID integer not null references student(StudentID)
73);
74
75CREATE TABLE owner_post (
76 OwnerPostID integer not null primary key references post(PostID),
77 ApartmentID integer not null references apartment(ApartmentID),
78 OwnerID integer not null references apartment_owner(OwnerID)
79);
80
81CREATE TABLE apartment_photos (
82 PostID integer references owner_post(OwnerPostID) primary key,
83 PhotosURL varchar(1000)
84);
85
86CREATE TABLE moderates_posts_for (
87 CityID integer not null references city(CityID),
88 AdminID integer not null references administrator(AdminID),
89 primary key (CityID, AdminID)
90);
91
92CREATE TABLE student_signs (
93 StudentID integer not null references student(StudentID),
94 AgreementID integer not null references apartment_agreement(AgreementID),
95 primary key (StudentID, AgreementID)
96);