如何使用链接的MySql服务器更新SQL Server中的行

时间:2022-01-18 15:40:33

I created linked server between sql server and mysql.It will work fine for me. My question is when insert row in mysql table that time i want to update row in sql server table,

我在sql server和mysql之间创建了链接服务器。它对我来说很好用。我的问题是当我在mysql表中插入行时,我想更新sql server表中的行,

Like in mysql table name 'abc' when in this table new row insert that time in ms sql server table name is xyz and in this field name status by default true and when new row insert in the abc table that time in xyz table field name status will automatically update and status will change to false.

就像在mysql表名'abc'中一样,在这个表中新行插入那个时间在ms sql server表名中是xyz并且在这个字段名中状态默认为true,当新行插入abc表时那个时间在xyz表字段名中状态将自动更新,状态将更改为false。

My linked server name is MYLINK and it will work fine for me , I want to create trigger which update row in sql server,and how to create trigger for update row in the ms sql server.

我的链接服务器名称是MYLINK,它对我来说很好用,我想创建触发器来更新sql server中的行,以及如何在ms sql server中创建更新行的触发器。

2 个解决方案

#1


1  

ALTER TRIGGER [TriggerLocalServerTable]
   ON  dbo.[LocalServerTable]
    FOR INSERT
AS 

DECLARE @A varchar(4)
DECLARE @B varchar(4)
DECLARE @id int

BEGIN
 SELECT
 @A = A,
 @B = B,
 @id = id
 FROM inserted

 UPDATE  [LinkedServer].[Database].[dbo].[Table]
 SET A = @A, B = @B
 WHERE id = @id      
END

#2


1  

mysql cannot trigger anything else but mssql. But you can use SQL Agent to schedule a task, executed on sql server to select data from the linked mysql

除了mssql之外,mysql不能触发任何其他内容。但是您可以使用SQL Agent来安排在sql server上执行的任务,以从链接的mysql中选择数据

#1


1  

ALTER TRIGGER [TriggerLocalServerTable]
   ON  dbo.[LocalServerTable]
    FOR INSERT
AS 

DECLARE @A varchar(4)
DECLARE @B varchar(4)
DECLARE @id int

BEGIN
 SELECT
 @A = A,
 @B = B,
 @id = id
 FROM inserted

 UPDATE  [LinkedServer].[Database].[dbo].[Table]
 SET A = @A, B = @B
 WHERE id = @id      
END

#2


1  

mysql cannot trigger anything else but mssql. But you can use SQL Agent to schedule a task, executed on sql server to select data from the linked mysql

除了mssql之外,mysql不能触发任何其他内容。但是您可以使用SQL Agent来安排在sql server上执行的任务,以从链接的mysql中选择数据