Inserting from SQL Server into MySQL results in first 2 rows blank - mysql

I am trying to insert data from a SQL Server table into a MySQL table; all columns insert correctly except for the first 2. I check the DB structure all matches. Recreated the tables, still have the same issue. Here is my statement:
insert openquery (MySQL, 'select DB, CreateDate, TaxDate, DocEntry, WddStatus, DocStatus, CardName, DocCur, DocTotal, U_NAME, Comments from ODRF_New')
Select
DB
,CreateDate
,TaxDate
,DocEntry
,WddStatus
,DocStatus
,Cardname
,DocCur
,DocTotal
,U_NAME
,Comments
From mashova_intranet.dbo.ODRF_New

Related

how i can insert a data from mssql to mysql database when insert data in msssql

I have two databases
MS SQL Server (with the table t1)
MySQL Server (with the table t2)
I want to insert the data into table t2 on MySQL Server when some data inserted into table t1 on MS SQL Server.
I have already tried to create the linked server and use the trigger but it is not working.
How can I do that?

is it possible to sync two tables in two linked server one from MySQL and MSSQL?

I have created two Linked server one from Mysql and the other from remote MSSQL. is it possible to sync tables in these two Linked server from different database?
To Insert data from MySQL to SQL Server, do something like
INSERT INTO SQLServerLinkedServer.database.schema.TableName(Col1,Col2)
SELECT Col1,Col2 FROM MySQLinkedServer...TableName
To Insert data from SQL Server to MySQL, do something like
INSERT INTO MySQLinkedServer...TableName(Col1,Col2)
SELECT Col1,Col2 FROM SQLServerLinkedServer.database.schema.TableName
You can compare these tables using key column. For Example insert missing records in MySQLinkedServer using something like this
INSERT INTO MySQLinkedServer...TableName(Col1,Col2)
SELECT T1.Col1,T2.Col2
FROM SQLServerLinkedServer.database.schema.TableName T1
LEFT JOIN MySQLinkedServer...TableName T2
ON T1.col1 = T2.col1
WHERE T2.col1 IS NULL

Specifiying the Table in an OpenQuery SQL Statement

I have the syntax that I need to run an insert on a linked server (mySQL is the Linked Server, MSSQL SSMS the host).
I've seen many examples but how do you specify the receiving table? (mySQL is the receiving server)
INSERT INTO OPENQUERY (mySQL, 'SELECT name FROM MSSQL_Table')
VALUES ('name');
The table and column specified in the SELECT part of the OPENQUERY statement will be used for the insert:
INSERT INTO OPENQUERY (mySQL, 'SELECT TargetColumn FROM mySQL_TargetTable')
VALUES ('name');
The example will insert the value 'name' into column TargetColumn of table mySQL_TargetTable at the mySQL linked server.

Link tables in SQL Server from MySQL using OPENQUERY to get just updated records

I am linking/copying tables from mysql to SQL Server. I have the linked servers setup and I can copy the tables. I need to know how to update only new records from the mysql database because there are 400,000 records on one table. Here is my query
INSERT INTO kiosk_test.dbo.CDS_STU_CLASS
FROM openquery(MYSQL, 'SELECT * FROM mycds.CDS_STU_CLASS')
How would you go about a stored procedure or query to update only the new records? I have tried researching the best I can to no real answer.
From Do I have to use OpenQuery to query a MySQL Linked Server from SQL Server?:
I think you can change openquery(MYSQL, 'SELECT * FROM mycds.CDS_STU_CLASS') to mycds..CDS_STU_CLASS
Then maybe this will work:
INSERT INTO kiosk_test.dbo.CDS_STU_CLASS
(SELECT _columns_
FROM mycds..CDS_STU_CLASS new
LEFT JOIN kiosk_test..CDS_STU_CLASS old
ON new.recordID = old.recordID
WHERE old.recordID IS NULL)
Untested...

How to identify the table name from last insert or update in sql server and mysql

In sql server and mysql
I want a query to identify the tables name which are affected using INSERT or UPDATE
Additional info:
1. I have more than two tables and all tables may not have indexes.
2. If a stored procedure execute I don't know what are the tables inserted or updated. But here I want to know.
Thanks.
You can do this in SQL server
SELECT TOP 1 *
FROM sys.dm_db_index_usage_stats
WHERE database_id = DB_ID( 'AdventureWorks')
AND OBJECT_ID in (select OBJECT_ID(name) from sys.tables)
ORDER BY last_user_update DESC
not sure about MYSQL
taken from here and here