-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcondominium_management.sql
113 lines (102 loc) · 3.5 KB
/
condominium_management.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
-- Create the database if it doesn't exist
CREATE DATABASE IF NOT EXISTS condominium_management;
-- Use the database
USE condominium_management;
-- Create the administrators table if it doesn't exist
CREATE TABLE IF NOT EXISTS administrators (
admin_id INT PRIMARY KEY AUTO_INCREMENT,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
phone VARCHAR(50),
email VARCHAR(255)
);
-- Create the condominiums table if it doesn't exist
CREATE TABLE IF NOT EXISTS condominiums (
condo_id INT PRIMARY KEY AUTO_INCREMENT,
condo_name VARCHAR(255) NOT NULL,
address VARCHAR(255) NOT NULL,
unit_count INT NOT NULL,
creation_date DATE NOT NULL,
admin_id INT,
contact_phone VARCHAR(50),
contact_email VARCHAR(255),
reserve_fund DECIMAL(10, 2),
status VARCHAR(50),
last_meeting_date DATE,
FOREIGN KEY (admin_id) REFERENCES administrators(admin_id)
);
-- Create the units table if it doesn't exist
CREATE TABLE IF NOT EXISTS units (
unit_id INT PRIMARY KEY AUTO_INCREMENT,
condo_id INT NOT NULL,
number VARCHAR(50) NOT NULL,
type VARCHAR(50) NOT NULL,
square_meters DECIMAL(10, 2),
owner_id INT,
FOREIGN KEY (condo_id) REFERENCES condominiums(condo_id),
FOREIGN KEY (owner_id) REFERENCES owners(owner_id)
);
-- Create the owners table if it doesn't exist
CREATE TABLE IF NOT EXISTS owners (
owner_id INT PRIMARY KEY AUTO_INCREMENT,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
phone VARCHAR(50),
email VARCHAR(255)
);
-- Create the expenses table if it doesn't exist
CREATE TABLE IF NOT EXISTS expenses (
expense_id INT PRIMARY KEY AUTO_INCREMENT,
unit_id INT NOT NULL,
month_year DATE NOT NULL,
total_amount DECIMAL(10, 2) NOT NULL,
payment_status VARCHAR(50) NOT NULL,
FOREIGN KEY (unit_id) REFERENCES units(unit_id)
);
-- Create the payments table if it doesn't exist
CREATE TABLE IF NOT EXISTS payments (
payment_id INT PRIMARY KEY AUTO_INCREMENT,
expense_id INT NOT NULL,
payment_date DATE NOT NULL,
amount DECIMAL(10, 2) NOT NULL,
payment_method VARCHAR(50) NOT NULL,
FOREIGN KEY (expense_id) REFERENCES expenses(expense_id)
);
-- Create the common_expenses table if it doesn't exist
CREATE TABLE IF NOT EXISTS common_expenses (
expense_id INT PRIMARY KEY AUTO_INCREMENT,
condo_id INT NOT NULL,
description VARCHAR(255) NOT NULL,
date DATE NOT NULL,
amount DECIMAL(10, 2) NOT NULL,
category VARCHAR(50) NOT NULL,
FOREIGN KEY (condo_id) REFERENCES condominiums(condo_id)
);
-- Create the meetings table if it doesn't exist
CREATE TABLE IF NOT EXISTS meetings (
meeting_id INT PRIMARY KEY AUTO_INCREMENT,
condo_id INT NOT NULL,
date DATE NOT NULL,
description TEXT,
decisions_made TEXT,
FOREIGN KEY (condo_id) REFERENCES condominiums(condo_id)
);
-- Create the notices table if it doesn't exist
CREATE TABLE IF NOT EXISTS notices (
notice_id INT PRIMARY KEY AUTO_INCREMENT,
condo_id INT NOT NULL,
title VARCHAR(255) NOT NULL,
description TEXT,
publication_date DATE NOT NULL,
FOREIGN KEY (condo_id) REFERENCES condominiums(condo_id)
);
-- Create the maintenance table if it doesn't exist
CREATE TABLE IF NOT EXISTS maintenance (
maintenance_id INT PRIMARY KEY AUTO_INCREMENT,
condo_id INT NOT NULL,
description TEXT NOT NULL,
scheduled_date DATE NOT NULL,
provider VARCHAR(255),
estimated_cost DECIMAL(10, 2),
FOREIGN KEY (condo_id) REFERENCES condominiums(condo_id)
);