-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_organization.sql
More file actions
60 lines (49 loc) · 1.25 KB
/
data_organization.sql
File metadata and controls
60 lines (49 loc) · 1.25 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
DROP TABLE IF EXISTS loan_payments;
DROP TABLE IF EXISTS loans;
DROP TABLE IF EXISTS transactions;
DROP TABLE IF EXISTS accounts;
DROP TABLE IF EXISTS customers;
CREATE TABLE customers (
customer_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
address VARCHAR(100),
city VARCHAR(50),
state VARCHAR(50),
zip VARCHAR(20)
);
SELECT * FROM customers;
CREATE TABLE accounts (
account_id INT PRIMARY KEY,
customer_id INT,
account_type VARCHAR(50),
balance DECIMAL(10, 2),
FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
);
SELECT * FROM accounts;
CREATE TABLE transactions (
transaction_id INT PRIMARY KEY,
account_id INT,
transaction_date DATE,
transaction_amount DECIMAL(10, 2),
transaction_type VARCHAR(10),
FOREIGN KEY (account_id) REFERENCES accounts(account_id)
);
SELECT * FROM transactions;
CREATE TABLE loans (
loan_id INT PRIMARY KEY,
customer_id INT,
loan_amount DECIMAL(10, 2),
interest_rate DECIMAL(5, 2),
loan_term INT,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
);
SELECT * FROM loans;
CREATE TABLE loan_payments (
payment_id INT PRIMARY KEY,
loan_id INT,
payment_date DATE,
payment_amount DECIMAL(10, 2),
FOREIGN KEY (loan_id) REFERENCES loans(loan_id)
);
SELECT * FROM loan_payments;