How to refer to a "new", "old" string for triggers on a SQL server?

SO I'm new to SQLite from SQLite, and I'm used to using keywords New | Old I saw that some people use the value insertedfor the new line, but this only applies to the insert, not the update. Howe can I get something like the Newone I'm using in this query?

create trigger ports_country_id_in_check
on [SISTEMA].Puerto
after insert, update
AS
BEGIN
  update [SISTEMA].Puerto
  set country_id = (select secuencia from [SISTEMA].Pais where codigo = New.pais_asociado)
  where [SISTEMA].Puerto.secuencia = New.secuencia
end
+1
source share
2 answers

The insert will also apply to the update. One updated row will be considered as a deleted and inserted row. Thus, you can check what happened and what it is now.

+3
source
create trigger ports_country_id_in_check
on [SISTEMA].Puerto
after insert, update
AS
BEGIN
  Declare @pais_asociado, @secuencia int

  select @pais_asociado = Puerto.pais_asociado, @secuencia = Puerto.secuencia
  from Puerto join inserted
  where Puerto.secuencia = inserted.secuencia

  update [SISTEMA].Puerto
  set country_id = (select secuencia from [SISTEMA].Pais where codigo = @pais_asociado)
  where [SISTEMA].Puerto.secuencia = @secuencia
end
0
source

All Articles