-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbank_db.sql
64 lines (55 loc) · 2.18 KB
/
bank_db.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
CREATE DATABASE IF NOT EXISTS bank_db;
USE bank_db;
CREATE TABLE IF NOT EXISTS customers (
customers_id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
customers_name VARCHAR(255) NOT NULL,
customers_dob DATE NOT NULL,
customers_username VARCHAR(50) NOT NULL UNIQUE,
customers_email VARCHAR(255) NOT NULL UNIQUE,
customers_address VARCHAR(255) NOT NULL,
customers_password VARCHAR(64) NOT NULL
);
CREATE TABLE IF NOT EXISTS employees (
employees_id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
employees_name VARCHAR(255) NOT NULL,
employees_dob DATE NOT NULL,
employees_username VARCHAR(50) NOT NULL UNIQUE,
employees_email VARCHAR(255) NOT NULL UNIQUE,
employees_password VARCHAR(64) NOT NULL
);
CREATE TABLE IF NOT EXISTS admins (
admins_id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
admins_name VARCHAR(255) NOT NULL,
admins_username VARCHAR(50) NOT NULL UNIQUE,
admins_email VARCHAR(255) NOT NULL UNIQUE,
admins_password VARCHAR(64) NOT NULL
);
CREATE TABLE IF NOT EXISTS accounts (
accounts_id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
account_number BIGINT UNSIGNED UNIQUE,
customers_id INT UNSIGNED NOT NULL,
employees_id INT UNSIGNED,
balance DECIMAL(13,2) NOT NULL,
is_active BOOLEAN NOT NULL DEFAULT FALSE,
FOREIGN KEY (customers_id) REFERENCES customers(customers_id),
FOREIGN KEY (employees_id) REFERENCES employees(employees_id)
);
CREATE TABLE appointments (
appointment_id INT AUTO_INCREMENT PRIMARY KEY,
customers_id INT UNSIGNED,
employees_id INT UNSIGNED,
appointment_date VARCHAR(255),
FOREIGN KEY (customers_id) REFERENCES customers (customers_id),
FOREIGN KEY (employees_id) REFERENCES employees (employees_id)
);
CREATE TABLE IF NOT EXISTS messages (
message_id INT PRIMARY KEY AUTO_INCREMENT,
customers_id INT UNSIGNED,
employees_id INT UNSIGNED,
messageContent VARCHAR(255),
FOREIGN KEY (customers_id) REFERENCES customers(customers_id),
FOREIGN KEY (employees_id) REFERENCES employees(employees_id)
);
ALTER TABLE accounts MODIFY COLUMN employees_id INT NULL;
INSERT INTO admins (admins_id, admins_name, admins_username, admins_email, admins_password)
VALUES (0, 'admin', 'admin', '[email protected]', SHA2('admin', 256));