I need to make a procedure
that instantiates the cli_TotalCompras
column of the client table with the customer's total (in value).
vendaProduto
table I have the value ( vpr_ValorUnit
), the quantity ( vpr_Quantidade
), and the sales ID ( ven_ID
) associated with table venda
that contains the customer you purchased ( cli_ID
).
How should I do it?
Table cliente
:
create table cliente (
cli_ID int not null constraint PKCliente primary key,
cli_Nome varchar(80) not null,
cli_Sexo char(01) check (cli_Sexo in('M', 'F')),
cli_Nascimento date Not null,
cid_ID int not null,
cli_Email varchar(100),
cli_Fixo varchar(11),
cli_Celular varchar(11),
cli_TotalCompras decimal(10,2);
constraint fkCliCid foreign key(cid_Id) references cidade(cid_Id));
Table venda
:
create table venda (
ven_ID int not null identity (1,1) constraint PKVenda primary key,
cli_ID int not null,
fun_ID int not null,
ven_Data date not null,
constraint fkVenCli foreign key (cli_ID) references cliente(cli_ID),
constraint fkVenFun foreign key (fun_ID) references funcionario(fun_ID));
Table vendaProduto
:
create table vendaProduto (
vpr_ID int identity (1,1) constraint PKVendaProduto primary key,
ven_ID int not null,
liv_ID int not null,
vpr_Quantidade int,
vpr_ValorUnit decimal(15,2),
constraint fkItvVen foreign key (ven_ID) references venda(ven_ID),
constraint fkItvliv foreign key (liv_ID) references livro(liv_ID));