IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_alarm_message_delete]') AND type = 'TR')
DROP TRIGGER [dbo].[mps_alarm_message_delete]
GO

   
CREATE trigger [dbo].[mps_alarm_message_delete] on [dbo].[mps_alarm_message] for delete as
begin
   insert into mps_alarm_message_history(almmsg_cmpid,
almmsg_almid,
almmsg_type,
almmsg_text,
almmsg_date,
almmsg_cuid,
almmsg_identkey,
almmsg_title,
almmsg_category,
almmsg_read,
almmsg_lastdate,
almmsg_sndcuid,
almmsg_sndname,
almmsg_objtype,
almmsg_ctgid,
almmsg_ctgid2,
almmsg_objid ) 
   select almmsg_cmpid,
almmsg_almid,
almmsg_type,
almmsg_text,
almmsg_date,
almmsg_cuid,
almmsg_identkey,
almmsg_title,
almmsg_category,
almmsg_read,
almmsg_lastdate,
almmsg_sndcuid,
almmsg_sndname,
almmsg_objtype,
almmsg_ctgid,
almmsg_ctgid2,
almmsg_objid   
from deleted 
end