-
Notifications
You must be signed in to change notification settings - Fork 0
/
expense_tracker.sql
45 lines (39 loc) · 1.15 KB
/
expense_tracker.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
-- Active: 1703155206960@@127.0.0.1@3306
CREATE DATABASE ExpenseTracker DEFAULT CHARACTER SET = 'utf8mb4';
USE ExpenseTracker;
-- Code for Expenses Table
CREATE TABLE Expenses (
ID INT AUTO_INCREMENT PRIMARY KEY,
CategoryID INT,
Date DATE NOT NULL,
Amount DECIMAL(10, 2) NOT NULL,
Description TEXT
);
-- Code for Categories Table
CREATE TABLE Categories (
CategoryID INT AUTO_INCREMENT PRIMARY KEY,
CategoryName VARCHAR(255) NOT NULL UNIQUE
);
-- Adding Foreign Key Constraint to Expenses Table
ALTER TABLE Expenses
ADD CONSTRAINT fk_expense_category
FOREIGN KEY (CategoryID)
REFERENCES Categories(CategoryID)
-- Code for Income Table
CREATE TABLE Income (
IncomeID INT AUTO_INCREMENT PRIMARY KEY,
IncomeSourceID INT,
Date DATE NOT NULL,
Amount DECIMAL(10, 2) NOT NULL,
Description TEXT
);
-- Code for IncomeSources Table
CREATE TABLE IncomeSources (
IncomeSourceID INT AUTO_INCREMENT PRIMARY KEY,
SourceName VARCHAR(255) NOT NULL UNIQUE
);
-- Adding Foreign Key Constraint to Income TABLE
ALTER TABLE Income
ADD CONSTRAINT fk_income_source
FOREIGN KEY (IncomeSourceID)
REFERENCES IncomeSources(IncomeSourceID)