-1
I need to create a Rigger that devalues the value of the apartment when a garage linked to it is deleted, I have the following tables:
create table apartamento (
numero varchar(5) not null,
tipo varchar(20) default null,
codigo_cond int(5) default null,
valor double(10,2) default '0.00',
primary key (numero),
key fk_ap_cond (codigo_cond),
constraint fk_ap_cond foreign key (codigo_cond) references condominio (codigo)
);
create table garagem (
numero int(3) not null auto_increment,
tipo varchar(20) default null,
numero_ap varchar(5) default null,
primary key (numero),
key fk_gar_apartamento (numero_ap),
constraint fk_gar_apartamento foreign key (numero_ap) references apartamento (numero)
);
And so far my Rigger is like this, I’m having trouble applying the condition of the garage to be deleted to devalue the price:
CREATE TRIGGER
`imobiliaria`.`desv_apartamento` AFTER DELETE ON `apartamento`
FOR EACH ROW
BEGIN
UPDATE apartamento.valor
IF
END IF;
END
What is the command of
update
what will you use when deleting? You want to decrease a percentage of the value?– Clarck Maciel
Exactly I intend to decrease the percentage of the value
– Guilherme Coutinho De Moura
Something like Begin Update apartment set value = value * . 95 Where number = old.numero_ap;end;
– Motta