SQL Insert/Update/Delete Trigger Efficiency

Igorlbg

New Member
In our application at the database level, I have a table called Installments in schema Billing and Billing_History.The trigger shown is on the Installments table in the Billing Schema. What this does is everytime a record is inserted/updated in the billing schema it is also written into the history file.If the record is deleted from the billing table it is written to the history table with a "Deleted" indicator = true.I think that the "If Not Exists (Select * from Inserted) is killing my performance as more records get added. Is there a more effecient was to write this trigger?\[code\]Create TRIGGER [Billing].[Installments_InsertDeleteUpdate_History]ON [Billing].[Installments]AFTER INSERT, DELETE, UPDATEAS BEGINInsert Into Billing_History.Installments Select *, GetDate(), 0 From InsertedIf Not Exists (Select * From Inserted) Insert Into Billing_History.Installments Select *, GetDate(), 1 From DeletedSET NOCOUNT ON;-- Insert statements for trigger here\[/code\]END
 
Top