Hello, wounder if anyone have already try it.
I have some software doing insert in a table and it can t be change to make an update.
I would catch these insert within a trigger on my table, and turn this insert into a simple update. But I can t find how to deal with rollback transaction to cancel actual insert at same time doing my new update inside my trigger
Say my table look like this :
ID Value
1 10
2 20
3 30
Command being send :
INSERT INTO table (ID,Value)
SELECT 1, 33
Catch in trigger
CREATE TRIGGER [myTrigger] ON [dbo].
FOR INSERT
AS
Update myTable
set myTable.value = ins.value
from table myTable, inserted ins
where myTable.ID = ins.ID
<<Insert here whatever rollback transaction to cancel any insert done>>
Final result:
ID Value
1 33
2 20
3 30
I have some software doing insert in a table and it can t be change to make an update.
I would catch these insert within a trigger on my table, and turn this insert into a simple update. But I can t find how to deal with rollback transaction to cancel actual insert at same time doing my new update inside my trigger
Say my table look like this :
ID Value
1 10
2 20
3 30
Command being send :
INSERT INTO table (ID,Value)
SELECT 1, 33
Catch in trigger
CREATE TRIGGER [myTrigger] ON [dbo].
FOR INSERT
AS
Update myTable
set myTable.value = ins.value
from table myTable, inserted ins
where myTable.ID = ins.ID
<<Insert here whatever rollback transaction to cancel any insert done>>
Final result:
ID Value
1 33
2 20
3 30