CREATE TRIGGER myInsertTrigger
ON [MSSQLDB].[dbo].[t1]
FOR INSERT,UPDATE
AS
DECLARE @ID int
SELECT @ID = (SELECT [id] FROM Inserted)
PRINT @ID
IF ( @ID >= 5000 ) AND ( @ID < 5999 )
BEGIN
SET XACT_ABORT ON
BEGIN TRANSACTION
INSERT INTO
OPENQUERY([MYSQL-REMOTE],'
SELECT fieldmy1, fieldmy2
FROM t1')
SELECT fieldms1, fieldms2
FROM Inserted
DELETE FROM [MSSQLDB].[dbo].[t1] WHERE [ID] = @ID
COMMIT TRANSACTION
END |