Any help appreciated.
I'm creating a helpdesk solution where i am extracting emails through Vb.net service from MS Exchange into SQL using Exchange API. The following query works fine and in SQL Server 2012, i have the MessageID column set to unique, indexed and ignore duplicate keys set to yes.
cmd.CommandText = "INSERT INTO Tickets ([Oid], [MessageID]) VALUES (@GuidValue, LEFT('" & E_ID & "', 255))"
The service grabs the most recent 10 emails and pops them into SQL
i've created a trigger on the table Tickets to insert a value of 1 in a column called InsertFlag for new records inserted through the service
Issue
the windows service obtains the 10 most recent emails every 10 minutes and inserts them in an SQL Table called Tickets
let's say on the next windows service run, there are only 2 new emails
the trigger still seems to update the other 8 existing records also
Trigger
USE Helpdesk
GO
CREATE TRIGGER InsertFlagTrigger
ON dbo.Tickets
AFTER INSERT
AS
DECLARE @insertflag int
Set @insertflag = '1'
BEGIN
update Tickets
set InsertedFlag = @insertflag
END
GO
Is it the Trigger causing the issue or is SQL ignoring duplicate keys set to yes and still updating the 10 records if only 2 new records are new ?
Many thanks
I'm creating a helpdesk solution where i am extracting emails through Vb.net service from MS Exchange into SQL using Exchange API. The following query works fine and in SQL Server 2012, i have the MessageID column set to unique, indexed and ignore duplicate keys set to yes.
cmd.CommandText = "INSERT INTO Tickets ([Oid], [MessageID]) VALUES (@GuidValue, LEFT('" & E_ID & "', 255))"
The service grabs the most recent 10 emails and pops them into SQL
i've created a trigger on the table Tickets to insert a value of 1 in a column called InsertFlag for new records inserted through the service
Issue
the windows service obtains the 10 most recent emails every 10 minutes and inserts them in an SQL Table called Tickets
let's say on the next windows service run, there are only 2 new emails
the trigger still seems to update the other 8 existing records also
Trigger
USE Helpdesk
GO
CREATE TRIGGER InsertFlagTrigger
ON dbo.Tickets
AFTER INSERT
AS
DECLARE @insertflag int
Set @insertflag = '1'
BEGIN
update Tickets
set InsertedFlag = @insertflag
END
GO
Is it the Trigger causing the issue or is SQL ignoring duplicate keys set to yes and still updating the 10 records if only 2 new records are new ?
Many thanks