tengo que crear un trigger asociado a la tabla pedidos de manera que cuando se actualice un registro de la tabla pedidos lo actualice en la tabla detallepedidos, lo he intentado de la siguiente forma pero no hay manera, si alguien lo pudiera resolver….
drop table if exists updatepedidos; create table updatepedidos ( CodigoPedido integer NOT NULL, FechaPedido date NOT NULL, FechaEsperada date NOT NULL, FechaEntrega date DEFAULT NULL, Estado varchar(15) NOT NULL, Comentarios text, CodigoCliente integer NOT NULL, PRIMARY KEY (CodigoPedido), CONSTRAINT Pedidos_Cliente FOREIGN KEY (CodigoCliente) REFERENCES Clientes (CodigoCliente) ); drop trigger if exists controlpedidos; DELIMITER // create trigger controlpedidos before update on pedidos for each row begin if new.CodigoPedido<>old.CodigoPedido then insert into updatepedidos values (new.CodigoPedido, old.FechaPedido, old.FechaEsperada, old.FechaEntrega, old.Estado, old.Comentarios, old.CodigoCliente); end if; if new.FechaPedido<>old.FechaPedido then insert into updatepedidos values (old.CodigoPedido, new.FechaPedido, old.FechaEsperada, old.FechaEntrega, old.Estado, old.Comentarios, old.CodigoCliente); end if; if new.FechaEsperada<>old.FechaEsperada then insert into updatepedidos values (old.CodigoPedido, old.FechaPedido, new.FechaEsperada, old.FechaEntrega, old.Estado, old.Comentarios, old.CodigoCliente); end if; if new.FechaEntrega<>old.FechaEntrega then insert into updatepedidos values (old.CodigoPedido, old.FechaPedido, old.FechaEsperada, new.FechaEntrega, old.Estado, old.Comentarios, old.CodigoCliente); end if; if new.Estado<>old.Estado then insert into updatepedidos values (old.CodigoPedido, old.FechaPedido, old.FechaEsperada, old.FechaEntrega, new.Estado, old.Comentarios, old.CodigoCliente); end if; if new.Comentarios<>old.Comentarios then insert into updatepedidos values (old.CodigoPedido, old.FechaPedido, old.FechaEsperada, old.FechaEntrega, old.Estado, new.Comentarios, old.CodigoCliente); end if; if new.CodigoCliente<>old.CodigoCliente then insert into updatepedidos values (old.CodigoPedido, new.FechaPedido, old.FechaEsperada, old.FechaEntrega, old.Estado, old.Comentarios, new.CodigoCliente); end if; end// DELIMITER ; update pedidos set CodigoCliente=22 where CodigoPedido=1;