I have the following table called Movies :
(id int, nombre varchar(50), genero varchar (50), clasificacion char(1), año int)
I have this trigger to validate that only one field can be updated at a time in that table.
Would there be any way to optimize this code so as not to use as many if?
Suppose that tomorrow I have a table of 40 columns.
create trigger tr_peliculasactulizacion on peliculas for update
as
begin
declare @conta int=0
if update(id)
select @conta+=1
if update (nombre)
select @conta+=1
if update (genero)
select @conta+=1
if update(clasificacion)
select @conta+=1
if update(año)
select @conta+=1
if @conta>1
begin
rollback tran
raiserror ('solo se puede actualizar un campo a la vez', 16, 1);
end
end