DDL: kreiranje.sql

File kreiranje.sql, 2.7 KB (added by 211228, 6 weeks ago)
Line 
1drop table if exists Dorm_User;
2drop table if exists Student;
3drop table if exists Employee;
4drop table if exists Payment;
5drop table if exists Dorm_Document;
6drop table if exists Block;
7drop table if exists Room;
8drop table if exists RoomRequest;
9drop table if exists StudentTookRoom;
10
11create table Dorm_User(
12 u_id bigint primary key,
13 phone_number varchar(10) not null,
14 first_name varchar(30) not null,
15 last_name varchar(50) not null,
16 email varchar(1000) not null unique,
17 pass varchar(15) not null
18);
19
20create table Student(
21 u_id bigint primary key references Dorm_User(u_id),
22 faculty_name varchar(255) not null,
23 year_of_studies integer not null,
24 is_exempt boolean not null
25);
26
27create table Employee(
28 u_id bigint primary key references Dorm_User(u_id)
29);
30
31create table Payment(
32 p_id bigint primary key,
33 amount integer not null,
34 payment_date date not null,
35 student_id bigint,
36 payment_month varchar(15) not null,
37 constraint payment_fk_kon_student foreign key (student_id) references Student(u_id)
38);
39
40create table Dorm_Document(
41 d_id bigint primary key,
42 d_comment varchar(1000),
43 d_status varchar(10) not null,
44 upload_date date not null,
45 file_path varchar(1000) not null,
46 emp_id bigint,
47 student_id bigint,
48 constraint Dorm_Document_fkey_kon_Employee foreign key(emp_id) references Employee(u_id),
49 constraint Dorm_Document_fkey_kon_Student foreign key(student_id) references Student(u_id)
50);
51
52create table Block(
53 block_id char(1) primary key,
54 num_available_rooms integer not null
55);
56
57
58create table Room(
59 room_number integer,
60 block_id char(1),
61 is_available boolean not null,
62 capacity integer not null,
63 constraint Room_pkey primary key(room_number, block_id),
64 constraint Room_fk_kon_Block foreign key(block_id) references Block(block_id)
65);
66
67create table RoomRequest(
68 status varchar(10) not null,
69 roomate_email varchar(1000),
70 room_number integer,
71 block_id varchar(1),
72 employee_id bigint,
73 student_id bigint,
74 constraint RoomRequest_pkey primary key(room_number, block_id, student_id),
75 constraint student_id foreign key(student_id) references Student(u_id),
76 constraint StudentTookRoom_fkey_kon_Room foreign key(room_number, block_id) references Room(room_number, block_id),
77 constraint employee_id foreign key(employee_id) references Employee(u_id)
78);
79
80create table StudentTookRoom(
81 start_date date not null,
82 end_date date,
83 student_id bigint,
84 room_num integer,
85 block_id char(1),
86 constraint StudentTookRoom_pkey primary key(student_id, room_num, block_id),
87 constraint StudentTookRoom_fkey_kon_Student foreign key(student_id) references Student(u_id),
88 constraint StudentTookRoom_fkey_kon_Room foreign key(room_num, block_id) references Room(room_number, block_id)
89);
90
91
92
93
94
95
96
97
98