-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprova.sql
More file actions
51 lines (39 loc) · 1.53 KB
/
prova.sql
File metadata and controls
51 lines (39 loc) · 1.53 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
51
create database Prova2;
use Prova2;
create table Bancos(
Codigo int not null,
Nome varchar(45),
primary key(Codigo));
create table Pessoas(
CPF varchar(11) not null,
Nome varchar(45),
primary key(CPF));
create table Conta_Corrente(
Banco int not null,
Pessoa varchar(11),
numero int not null,
primary key(Banco,Pessoa,numero),
foreign key(Banco) references Bancos(Codigo),
foreign key(Pessoa) references Pessoas(CPF));
insert into Bancos(Codigo,Nome)
values(001,'Banco do Brasil'),
(033,'Santander'),
(237,'Bradesco'),
(341,'Itau');
insert into Pessoas(CPF,Nome)
values('86277635697','Jose da Silva'),
('88208811874','Manoel da Silva'),
('66516764743','Maria dos Santos');
insert into Conta_Corrente(Banco,Pessoa,numero)
values(033,'86277635697',98876788),
(237,'86277635697',96645727),
(341,'66516764743',9102947),
(001,'88208811874',8120938);
select Nome as B,Codigo from Bancos where Nome like 'B%';
update Pessoas set Nome ='Manoel da Silva Ferreira' where CPF='88208811874';
select * from Pessoas;
select count(codigo) as 'Qtd Bancos' from Bancos;
select nome from Pessoas right join conta_corrente on cpf=Pessoa where numero=9102947;
select B.nome as 'Nome do banco' from Bancos B inner join Conta_Corrente C on B.codigo=C.Banco
inner join Pessoas P on C.Pessoa=P.Cpf where P.cpf='66516764743';
select nome, Cpf, count(Cpf) as 'QTde Contas' from Pessoas full join Conta_Corrente on CPF=Pessoa group by cpf;