Fórum multiple rows in a singleton selection #57851
09/02/2007
0
CREATE TRIGGER VOLTAR_ESTOQUE_VENDA FOR ITENSMOVIMENTO ACTIVE BEFORE DELETE POSITION 0 AS declare cod integer = 0; begin SELECT OLD.COD FROM ITENSMOVIMENTO INTO :COD; end
A intençao nesse caso, é saber o código (PK) do registro deletado.
O que está errado nesta trigger?
Kopcheski
Curtir tópico
+ 0Posts
09/02/2007
Sremulador
CREATE TRIGGER VOLTAR_ESTOQUE_VENDA FOR ITENSMOVIMENTO ACTIVE BEFORE DELETE POSITION 0 AS declare cod integer = 0; begin SELECT OLD.COD FROM ITENSMOVIMENTO WHERE NEW.COD=??? INTO :COD DO SUEPEND; end
Gostei + 0
09/02/2007
Emerson Nascimento
não é necessário, visto que OLD é uma tabela temporária com os registros da tabela ITENSMOVIMENTO que estão sendo excluídos.
explique melhor o que você deseja fazer que talvez possamos dar alguma dica que te ajude na solução do seu problema.
Gostei + 0
09/02/2007
Kopcheski
Quando eu excluo um item da tabela ITENSMOVIMENTO, eu gostaria de saber qual registro foi deletado. Por isso eu usei old.cod. Sabendo qual item foi deletado, eu faço algumas outras operaçoes. Mas em resumo, eu preciso saber qual registro da tabela ITENSMOVIMENTO foi excluído. E de preferencia, através de triggers, já que o uso de procedures com hibernate é bem complicado. Muito complicado.
Gostei + 0
09/02/2007
Emerson Nascimento
publique a estrutura dessa tabela
Gostei + 0
09/02/2007
Kopcheski
CREATE TABLE ITENSMOVIMENTO ( COD INTEGER NOT NULL, QUANT FLOAT, PRC DOUBLE PRECISION, OPERACAO VARCHAR(1), ORCAMENTO_CODORC INTEGER, SERVICO_COD INTEGER ); ALTER TABLE ITENSMOVIMENTO ADD PRIMARY KEY (COD); ALTER TABLE ITENSMOVIMENTO ADD CONSTRAINT FKFAA9E71D155A10C2 FOREIGN KEY (ORCAMENTO_CODORC) REFERENCES ORCAMENTO (CODORC); ALTER TABLE ITENSMOVIMENTO ADD CONSTRAINT FKFAA9E71D3C3160B2 FOREIGN KEY (SERVICO_COD) REFERENCES SERVICO (COD);
Gostei + 0
09/02/2007
Emerson Nascimento
supondo que sua tabela de itens comportasse produtos de uma nota fiscal de saida/venda, o saldo em estoque poderia ser realimentado assim:
CREATE TRIGGER VOLTAR_ESTOQUE_VENDA FOR ITENSMOVIMENTO ACTIVE BEFORE DELETE POSITION 0 AS begin update ProdutoSaldo set Saldo = Saldo + OLD.Quant where Produto = OLD.COD end
Gostei + 0
11/02/2007
Kopcheski
enquanto postava aqui, estive tentanto dar um jeito nisso..
Muito obrigado pela ajuda! :)
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)