-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitDB.sql
More file actions
50 lines (39 loc) · 1.4 KB
/
initDB.sql
File metadata and controls
50 lines (39 loc) · 1.4 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
DROP DATABASE IF EXISTS masterdb;
CREATE DATABASE masterdb;
USE masterdb;
CREATE TABLE customers(
customerID int NOT NULL AUTO_INCREMENT,
firstName varchar(255) NOT NULL,
lastName varchar(255) NOT NULL,
username varchar(255) NOT NULL,
password varchar(255) NOT NULL,
balance float NOT NULL,
PRIMARY KEY (customerID),
UNIQUE KEY (username)
);
CREATE TABLE transactions(
transactionID int NOT NULL AUTO_INCREMENT,
customerID int NOT NULL,
amount int NOT NULL,
purchase_date TIMESTAMP NOT NULL,
PRIMARY KEY (transactionID),
FOREIGN KEY (customerID) REFERENCES customers(customerID)
);
CREATE TABLE superadmins(
adminID int NOT NULL AUTO_INCREMENT,
username varchar(255) NOT NULL,
PRIMARY KEY (adminID),
FOREIGN KEY (username) REFERENCES customers(username)
);
CREATE TABLE loggedCustomers(
token varchar(255) NOT NULL,
username varchar(255) NOT NULL
);
INSERT INTO customers VALUES (NULL,"Giulio", "Bianchini", "admin", "123456", "0");
INSERT INTO customers VALUES (NULL,"Dippy", "Dawg", "Pippo", "123456", "100");
INSERT INTO customers VALUES (NULL,"Donald", "Duck", "Paperino", "123456", "200");
INSERT INTO transactions VALUES (NULL,2,10,CURRENT_TIMESTAMP());
INSERT INTO transactions VALUES (NULL,2,20,CURRENT_TIMESTAMP());
INSERT INTO transactions VALUES (NULL,3,50,CURRENT_TIMESTAMP());
INSERT INTO transactions VALUES (NULL,3,70,CURRENT_TIMESTAMP());
INSERT INTO superadmins VALUES (1, "admin");