forked from alanomenezes/BlueBank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScript SQL BlueBank.sql
102 lines (89 loc) · 2.99 KB
/
Script SQL BlueBank.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
create database blue_bank;
use blue_bank;
#drop database blue_bank;
create table client (
id bigint not null auto_increment,
cep varchar(255),
cpfcnpj varchar(255),
email varchar(255),
name varchar(255),
password varchar(255),
phone_number varchar(255),
status integer,
type varchar(255),
unique key(cpfcnpj),
primary key (id)
);
create table account (
id bigint not null auto_increment,
account_type integer,
agency integer not null,
balance double precision not null,
date_for_reference datetime,
status integer,
client_id bigint,
primary key (id)
);
create table transaction (
id bigint not null auto_increment,
current_balance double precision not null,
data_agend_transacao datetime,
data_exec_transacao datetime,
previous_balance double precision not null,
transaction_date datetime not null,
transaction_type integer not null,
value double precision not null,
account_id bigint,
destination_account_id bigint,
primary key (id)
);
create table loan (
id bigint not null auto_increment,
borrowed_amount double precision not null,
end_date datetime not null,
fees double precision not null,
installments integer not null,
start_date datetime not null,
client_id bigint,
primary key (id)
);
alter table account add constraint fk_client foreign key (client_id) references client (id);
alter table loan add constraint fk_client2 foreign key (client_id) references client (id);
alter table transaction add constraint fk_account foreign key (account_id) references account (id);
alter table transaction add constraint fk_destination_account foreign key (destination_account_id) references account (id);
## Populando client ##
insert into client
( name, cpfcnpj, email, cep, phone_number, password, type)
values
("BlueBank", "02657489781", "[email protected]", "55006-700", "(11) 97889-6783","minhasenha123","PJ");
insert into client
( name, cpfcnpj, email, cep, phone_number, password, type)
values
("Joao", "15469876325", "[email protected]", "66008-800", "(11) 98670-8227","minhasenha123","PF");
## Populando account ##
insert into account
(account_type, agency, balance, date_for_reference, status, client_id)
values
(0, 1, 5000.0, "2021-12-08 21:00:00", 0, 1);
insert into account
(account_type, agency, balance, date_for_reference, status, client_id)
values
(0, 1, 5000.0, "2021-12-08 21:00:00",0, 2);
## Populando transaction ##
insert into transaction
(current_balance, previous_balance, transaction_date, transaction_type, value, account_id)
values
(4850.0, 5000.0, "2021-12-08 21:30:00", 0, 150.0, 2);
insert into transaction
(current_balance, previous_balance, transaction_date, transaction_type, value, account_id)
values
(5000.0, 4850.0, "2021-12-08 21:35:00", 1, 150.0, 2);
## Populando loan ##
insert into loan
(borrowed_amount, end_date, fees, installments, start_date, client_id)
values
(3000.0, "2022/03/25 21:00:00", 0.2, 3, "21-12-08 21:00:00", 2);
insert into loan
(borrowed_amount, end_date, fees, installments, start_date, client_id)
values
(4000.0, "2022/05/26 21:00:00", 0.2, 3, "22-03-26 21:00:00", 2);