if not exists(SELECT column_name from sys.syscolumn sc join sys.systable st on sc.table_id = st.table_id where LCase(table_name) = LCase('Hotels') and LCase(column_name) = LCase('PayChislo')) then alter table Hotels add "PayChislo" integer default 0; end if; go IF (EXISTS(Select * from sys.systrigger where LCase(trigger_name) = LCase('TrigHotelsPayChislo'))) THEN Drop trigger TrigHotelsPayChislo END IF GO create trigger TrigHotelsPayChislo after update order 3 on DBA.Hotels referencing new as HNEW old as HOLD for each row begin declare @HotelId integer; if (HNEW.PayChislo <> HOLD.PayChislo) then select IntStojnost into @HotelId from Registers where RegisterName='HotelID'; if HNEW.Hotel_ID = @HotelId then update Registers set IntStojnost = HNEW.PayChislo where RegisterName='PayChislo'; set bvrPayChislo = HNEW.PayChislo; end if; end if; end go