简体   繁体   中英

Alternative to openquery delete for MySQL

I am running Microsoft SQL Server 2012 and am attempting to run an openquery delete command into a MySQL database:

delete openquery(MyLinkedServer, 'select * from table_to_delete_from');

This works, however is utterly, painfully slow to the point that it is unviable. The dataset involved is far too large, and doing the above requires that all of the MySQL data to be deleted must be fetched over VPN to the MSSQL server.

When running this command directly from the MySQL server, it is observed to be over 5x faster, which is viable.

How can I invoke a delete command from MSSQL over to the MySQL linked server without having to copy the datasets? Perhaps running a stored procedure of sorts on the MySQL side? Does that work with openquery ?

试试这个:

exec ('delete from table_to_delete_from') at MyLinkedServer

another case for SSIS, whenever i need to communicate to MYSQL. and insist to have truncate process on MYSQL table. i provide the procedure like below, :

CREATE PROCEDURE [dbo].[Usp_DeleteDynamicTable] @sourceTable nvarchar(max)
AS
BEGIN
DECLARE @SQL nvarchar(max)
SET @SQL='truncate table '+ @sourceTable
exec (@SQL) at MYSQL  --MYSQL is my linked server names
END

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM