2
I need to make a procedure
to install the column cli_TotalCompras
of the customer table with the total (in value) of the customer’s purchases.
On the table vendaProduto
have the value (vpr_ValorUnit
), the amount (vpr_Quantidade
) and the sale ID (ven_ID
) associated with the table venda
which contains the customer you purchased (cli_ID
).
Like I should do?
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));
Is it to assemble stored procedure that will be called to calculate the total value of customer purchases or create procedure Rigger that, occurring a given event, should update the cli_TotalCompras column? In the application there is an event that signals final sales? It would be the best time to calculate the total of those sales.
– José Diz
Was any of the answer helpful? Don’t forget to choose one and mark it so it can be used if someone has a similar question!
– Sorack