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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s