-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
67 lines (58 loc) · 2.5 KB
/
schema.sql
File metadata and controls
67 lines (58 loc) · 2.5 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
-- Schema for Users Table
CREATE TABLE Users (
UserID INT PRIMARY KEY AUTO_INCREMENT,
FirstName VARCHAR(255) NOT NULL,
LastName VARCHAR(255) NOT NULL,
Email VARCHAR(255) UNIQUE NOT NULL,
Password VARCHAR(255) NOT NULL
);
-- Schema for Accounts Table
CREATE TABLE Accounts (
AccountID INT PRIMARY KEY AUTO_INCREMENT,
UserID INT NOT NULL,
AccountName VARCHAR(255) NOT NULL,
Balance DECIMAL(10,2) NOT NULL,
FOREIGN KEY (UserID) REFERENCES Users(UserID)
);
-- Schema for Categories Table
CREATE TABLE Categories (
CategoryID INT PRIMARY KEY AUTO_INCREMENT,
UserID INT NOT NULL,
CategoryName VARCHAR(255) NOT NULL,
FOREIGN KEY (UserID) REFERENCES Users(UserID)
);
-- Schema for Transactions Table
CREATE TABLE Transactions (
TransactionID INT PRIMARY KEY AUTO_INCREMENT,
UserID INT NOT NULL,
AccountID INT NOT NULL,
CategoryID INT,
Amount DECIMAL(10,2) NOT NULL,
Date DATE NOT NULL,
Description VARCHAR(255),
FOREIGN KEY (UserID) REFERENCES Users(UserID),
FOREIGN KEY (AccountID) REFERENCES Accounts(AccountID),
FOREIGN KEY (CategoryID) REFERENCES Categories(CategoryID)
);
-- Create indexes
CREATE INDEX idx_user_email ON Users(Email);
CREATE INDEX idx_account_user ON Accounts(UserID);
CREATE INDEX idx_category_user ON Categories(UserID);
CREATE INDEX idx_transaction_user ON Transactions(UserID);
CREATE INDEX idx_transaction_account ON Transactions(AccountID);
CREATE INDEX idx_transaction_category ON Transactions(CategoryID);
-- Sample Data Insertion
-- Inserting sample data into Users
INSERT INTO Users (FirstName, LastName, Email, Password) VALUES ('John', 'Doe', '[email protected]', 'password123');
INSERT INTO Users (FirstName, LastName, Email, Password) VALUES ('Jane', 'Smith', '[email protected]', 'password123');
-- Inserting sample data into Accounts
INSERT INTO Accounts (UserID, AccountName, Balance) VALUES (1, 'Checking', 1000.00);
INSERT INTO Accounts (UserID, AccountName, Balance) VALUES (2, 'Savings', 5000.00);
-- Inserting sample data into Categories
INSERT INTO Categories (UserID, CategoryName) VALUES (1, 'Groceries');
INSERT INTO Categories (UserID, CategoryName) VALUES (2, 'Utilities');
-- Inserting sample data into Transactions
INSERT INTO Transactions (UserID, AccountID, CategoryID, Amount, Date, Description)
VALUES (1, 1, 1, 100.00, '2024-06-01', 'Grocery shopping');
INSERT INTO Transactions (UserID, AccountID, CategoryID, Amount, Date, Description)
VALUES (2, 2, 2, 150.00, '2024-06-01', 'Utility bill');