Query MySQL Database From SQL server

Follow the following instructions to create a linked server between
SQL Server Management Studio and a MySQL database –

https://robbamforth.wordpress.com/2008/10/17/connect-to-mysql-database-from-sql-server/

Use the OPENQUERY command to retrieve data from the MySQL database.

The syntax is as follows, where DATA is the name for the ODBC Linked Server
previously created. TABLE is the name of the MySQL table:

SELECT *
FROM
OPENQUERY(DATA, ‘select * from TABLE’) 

 

You can select the data into a standard SQL table:


SELECT *
INTO WEBDOWNLOAD.DBO.DATA
FROM
OPENQUERY(DATA, ‘select * from TABLE’)

 

The OPENQUERY command goes much further than allowing selections on the MySQL data set, it also enable manipulation of the data.

The following command deletes the data in the MySQL database ‘TABLE’ using the ‘DATA’ ODBC:

DELETE FROM OPENQUERY(DATA,‘select * from TABLE’) where id = ’10’

 

 

Advertisements