-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPersonal_Expense.sql
More file actions
116 lines (104 loc) · 3.91 KB
/
Personal_Expense.sql
File metadata and controls
116 lines (104 loc) · 3.91 KB
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
114
115
CREATE DATABASE IF NOT EXISTS personal_finance;
USE personal_finance;
CREATE TABLE IF NOT EXISTS users (
user_id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
email VARCHAR(100) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS accounts (
account_id INT AUTO_INCREMENT PRIMARY KEY,
account_name VARCHAR(100) NOT NULL,
account_type ENUM('checking', 'savings', 'credit', 'investment') NOT NULL,
balance DECIMAL(15, 2) NOT NULL DEFAULT 0.00,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS expenses (
expense_id INT AUTO_INCREMENT PRIMARY KEY,
account_id INT,
amount DECIMAL(15, 2) NOT NULL,
category VARCHAR(100) NOT NULL,
expense_date DATE NOT NULL,
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (account_id) REFERENCES accounts(account_id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS subscriptions (
subscription_id INT AUTO_INCREMENT PRIMARY KEY,
account_id INT,
service_name VARCHAR(100) NOT NULL,
amount DECIMAL(15, 2) NOT NULL,
billing_cycle ENUM('monthly', 'yearly') NOT NULL,
next_billing_date DATE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (account_id) REFERENCES accounts(account_id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS groceries (
grocery_id INT AUTO_INCREMENT PRIMARY KEY,
account_id INT,
item_name VARCHAR(100) NOT NULL,
quantity INT NOT NULL,
price DECIMAL(15, 2) NOT NULL,
purchase_date DATE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (account_id) REFERENCES accounts(account_id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS investments (
investment_id INT AUTO_INCREMENT PRIMARY KEY,
account_id INT,
investment_type ENUM('stock', 'bond', 'mutual_fund', 'real_estate') NOT NULL,
amount DECIMAL(15, 2) NOT NULL,
investment_date DATE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (account_id) REFERENCES accounts(account_id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS income (
income_id INT AUTO_INCREMENT PRIMARY KEY,
account_id INT,
amount DECIMAL(15, 2) NOT NULL,
source VARCHAR(100) NOT NULL,
income_date DATE NOT NULL,
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (account_id) REFERENCES accounts(account_id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS savings (
saving_id INT AUTO_INCREMENT PRIMARY KEY,
account_id INT,
amount DECIMAL(15, 2) NOT NULL,
goal VARCHAR(100),
saving_date DATE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (account_id) REFERENCES accounts(account_id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS bills (
bill_id INT AUTO_INCREMENT PRIMARY KEY,
account_id INT,
amount DECIMAL(15, 2) NOT NULL,
bill_type VARCHAR(100) NOT NULL,
due_date DATE NOT NULL,
paid BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (account_id) REFERENCES accounts(account_id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS loans (
loan_id INT AUTO_INCREMENT PRIMARY KEY,
account_id INT,
loan_type VARCHAR(100) NOT NULL,
amount DECIMAL(15, 2) NOT NULL,
interest_rate DECIMAL(5, 2) NOT NULL,
start_date DATE NOT NULL,
end_date DATE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (account_id) REFERENCES accounts(account_id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS extra_expenses (
extra_expense_id INT AUTO_INCREMENT PRIMARY KEY,
account_id INT,
amount DECIMAL(15, 2) NOT NULL,
reason VARCHAR(255) NOT NULL,
expense_date DATE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (account_id) REFERENCES accounts(account_id) ON DELETE CASCADE
);