0
我想用觸發器中每個選擇行的值做一個操作,但我不知道如何開始設計這個算法。如何對select中的每一行執行操作?
create trigger trigger_updCompleta
after update on tableA
for each row
begin
update tableB
set tableB.est='reserved'
where tableB.id_e= attr1_from_a_row_of_select and
tableB.num_a= attr2_from_a_row_of_select and
tableB.num_g= attr3_from_a_row_of_select;
end//
這是從中選擇要比較的值
select c.id_e, c.num_g, c.num_a, c.t from tableC as c
where c.id_r=tableA;
我的表是這個
CREATE TABLE IF NOT EXISTS tableA(
id_r INT NOT NULL,
id_c INT NOT NULL REFERENCES cliente (id_cliente),
completed BOOLEAN NOT NULL,
PRIMARY KEY (id_r)
);
CREATE TABLE IF NOT EXISTS tableB(
id_e INT NOT NULL REFERENCES grada (id_e),
num_g INT NOT NULL REFERENCES grada (num_g),
num_a INT NOT NULL,
est ENUM('reserved', 'libre', 'pre-reservado', 'deteriorado') NOT NULL DEFAULT 'libre',
PRIMARY KEY (id_e , num_g , num_a)
);
CREATE TABLE IF NOT EXISTS tableC(
id_r INT NOT NULL REFERENCES reserva (id_reserva),
id_e INT NOT NULL REFERENCES localidad (id_evento),
num_g INT NOT NULL REFERENCES localidad (num_grada),
num_a INT NOT NULL REFERENCES localidad (num_asiento),
t ENUM('bebe', 'infantil', 'adulto', 'parado', 'jubilado') NOT NULL REFERENCES precio (t),
PRIMARY KEY (id_r , id_e , num_g , num_a)
);
我想,當我TableA上更新行,自動將tableB.est的值更改爲reserved,對於tableB.id_e,tableB.num_a和tableB.num_g中的每個行都與選擇的值c.id_e,c.num_g和c.num_a相同
請問你的表看,結果是什麼你正在尋找? –
by'tableB.id_e = attr1_from_a_row_of_select'你的意思是做'tableB.id_e = NEW.attr1' –
不,我的意思是選擇返回的atribues之一 –