Although this is completed successfully on completion, it is not having the desired update.
CREATE TRIGGER Trigger1
On dbo.[table1]
FOR UPDATE
AS
Declare @Id int;
SELECT @Id = Issue_Id FROM dbo.[table1]
INSERT INTO dbo.[storage]
SELECT Id, Title, project, Problem
FROM dbo.[table2]
WHERE Id = @Id
Is there something I am doing wrong or that I can’t use variables within the scope of a trigger?
Many thanks
The others have correctly answered that you should be using
insertedand a join, to build a proper trigger. But:Based on your comments to other’s answers – you should never attempt to access any resource outside of your own database from a trigger, let along from another server.
Try to decouple the trigger activity from the cross server activity – say have your trigger add a row to a queue table (or use real service broker queues), and have an independent component be responsible for servicing these requests.
Otherwise, if there are any e.g. network issues, not only does your trigger break, but it forces a rollback for the original update also – it makes your local database unusable.
This also means that the independent component can cope with timeouts, and perform appropriate retries, etc.