-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcriandoBD.sql
63 lines (54 loc) · 2 KB
/
criandoBD.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
CREATE TABLE IF NOT EXISTS banco(
numero integer not null,
nome varchar(50) not null,
ativo boolean not null default TRUE,
data_criacao timestamp not null default current_timestamp,
primary key (numero)
);
create table if not exists agencia(
banco_numero integer not null,
numero integer not null,
nome varchar(80) not null,
ativo boolean not null default TRUE,
data_criacao timestamp not null default current_timestamp,
primary key (banco_numero, numero),
foreign key (banco_numero) references banco(numero)
);
create table if not exists cliente(
numero bigserial primary key,
nome varchar(120) not null,
email varchar(250) not null,
ativo boolean not null default TRUE,
data_criacao timestamp not null default current_timestamp
);
create table if not exists conta_corrente(
banco_numero integer not null,
agencia_numero integer not null,
numero bigint not null,
digito smallint not null,
cliente_numero bigint not null,
ativo boolean not null default TRUE,
data_criacao timestamp not null default current_timestamp,
primary key (banco_numero,agencia_numero,numero,digito,cliente_numero),
foreign key (banco_numero, agencia_numero) references agencia (banco_numero,numero),
foreign key (cliente_numero) references cliente(numero)
);
create table if not exists tipo_transacao(
id smallserial primary key,
nome varchar(50) not null,
ativo boolean not null default TRUE,
data_criacao timestamp not null default current_timestamp
);
create table if not exists cliente_transacoes(
id bigserial primary key,
banco_numero integer not null,
agencia_numero integer not null,
conta_corrente_numero bigint not null,
conta_corrente_digito smallint not null,
cliente_numero bigint not null,
tipo_transacao_id smallint not null,
valor numeric(15,2) not null,
data_criacao timestamp not null default current_timestamp,
foreign key (banco_numero, agencia_numero,conta_corrente_numero,conta_corrente_digito,cliente_numero)
references conta_corrente(banco_numero,agencia_numero,numero,digito,cliente_numero)
);