-1
I have this Trigger in Postgresql
and I’m having a hard time turning it into SQL Server
.
-- Trigger --
CREATE TRIGGER livro_original
BEFORE INSERT
ON tabela
FOR EACH ROW
EXECUTE PROCEDURE insere_valor_original();
CREATE OR REPLACE FUNCTION insere_valor_original()
RETURNS trigger AS
$BODY$
BEGIN
IF (new.es_original <= 0 OR new.es_original is null) THEN
new.es_original = new.id_codigo;
END IF;
RETURN NEW;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
I’m trying this way:
CREATE TRIGGER TRG_EXEMPLO ON tabela FOR INSERT AS
BEGIN
update inserted
set INSERTED.es_ORIGINAL = INSERTED.ID_CODIGO
where INSERTED.ID_CODIGO = INSERTED.ID_CODIGO
END
But I get this mistake:
INSERTED and DELETED logical tables cannot be updated