-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcreate.sql
41 lines (37 loc) · 1.19 KB
/
create.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
DROP DATABASE IF EXISTS db_paymybuddy ;
CREATE DATABASE db_paymybuddy;
USE db_paymybuddy;
CREATE TABLE user (
user_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
email VARCHAR(100) NOT NULL UNIQUE,
password VARCHAR(100),
firstname VARCHAR(50),
lastname VARCHAR(50),
balance DECIMAL(10, 2)
);
CREATE TABLE connection (
connection_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
fk_initializer_id INT NOT NULL,
fk_receiver_id INT NOT NULL,
starting_date DATETIME NOT NULL,
FOREIGN KEY (fk_initializer_id)
REFERENCES user (user_id)
ON DELETE NO ACTION ON UPDATE NO ACTION,
FOREIGN KEY (fk_receiver_id)
REFERENCES user (user_id)
ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE transaction (
transaction_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
fk_issuer_id INT NOT NULL,
fk_payee_id INT NOT NULL,
date DATETIME NOT NULL,
amount DECIMAL(10, 2) NOT NULL,
description VARCHAR(140),
FOREIGN KEY (fk_issuer_id)
REFERENCES user (user_id)
ON DELETE NO ACTION ON UPDATE NO ACTION,
FOREIGN KEY (fk_payee_id)
REFERENCES user (user_id)
ON DELETE NO ACTION ON UPDATE NO ACTION
);