-
Notifications
You must be signed in to change notification settings - Fork 923
/
Copy pathinit.sql
33 lines (28 loc) · 891 Bytes
/
init.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
CREATE TABLE clientes
(
id INT PRIMARY KEY,
nome VARCHAR(50) NOT NULL,
limite_conta INTEGER NOT NULL,
saldo INTEGER NOT NULL DEFAULT 0
);
CREATE TYPE TipoOperacao AS ENUM('c', 'd');
CREATE TABLE transacoes
(
id SERIAL PRIMARY KEY,
cliente_id INTEGER NOT NULL,
valor INTEGER NOT NULL,
tipo TipoOperacao NOT NULL,
descricao VARCHAR(10) NOT NULL,
criado_em TIMESTAMP NOT NULL DEFAULT NOW(),
CONSTRAINT fk_transactions_client_id
FOREIGN KEY (cliente_id) REFERENCES clientes (id)
);
CREATE INDEX idx_transacoes_cliente_id ON transacoes (cliente_id);
CREATE INDEX idx_transacoes_criado_em ON transacoes (criado_em);
INSERT INTO clientes (id, nome, limite_conta)
VALUES
(1, 'Van Hohenheim', 100000),
(2, 'Edward Elric', 80000),
(3, 'Alphonse Elric', 1000000),
(4, 'Roy Mustang', 10000000),
(5, 'Winry Rockbell', 500000);