Question : before update trigger to prevent a field edit

Can someone show me a sample of a trigger that at the time of an insert copies the value in field1 to field2 and also on an edit prevents field2 from being altered?

Lets assume both fields are INT


Thanks!

Answer : before update trigger to prevent a field edit

create TRIGGER MyTrig
ON mytable
FOR  INSERT
AS
BEGIN
UPDATE mytable
   SET field2 = inserted.field1
      FROM inserted, mytable
         WHERE inserted.keyvalue = mytable.keyvalue
             
END
Random Solutions  
 
programming4us programming4us