Insert into MySQL from MS SQL - mysql

I work on a SQL Server 2016. In this Server has a linkedserver connection to MySQL. Now I want to insert from a local mssql table to a MySQL table.
My code is:
INSERT OPENQUERY (
MYSQL_BEWERTUNG
,'SELECT PERSONALNR, EINSATZSART, KUNDENNR FROM tb_bewertung'
)
SELECT b.PERSONALNR
,b.DATUMVON
,b.KUNDENNR
FROM ext_bewertungen b
After that execution, I get an message that 136 rows are effected.
If I look into the MySQL table, I can't find the new rows. But if I look from the MS SQL server with
SELECT PERSONALNR
,EINSATZSART
,KUNDENNR
FROM OPENQUERY(MYSQL_BEWERTUNG, 'SELECT PERSONALNR, EINSATZSART, KUNDENNR
FROM tb_bewertung')
ORDER BY 1;
the new rows were shown.
Could someone explain me what am I doing wrong?
Thanks a lot!

Solved problem, the t-sql is right, my IT change the webserver and change in my holidays my linkedserver also, thats why i did not see any changes... thanks #MandyShaw for the idea if I am on the wrong server =)

Related

MySQL table value execution

I am doing a simple execution in MySQL workbench, the syntax is correct but nothing is happening.
select first name from employees;
only that but nothing is happening on the table. can someone what might be the problem?

Can not issue data manipulation statements with executeQuery - data studio/my sql connector error

I have a query that is running just fine in MySQL Workbench but am getting a data studio-related error once I try to run it in mysql connector within data studio. I’ve been trying to google around and ask on SO and data studio message boards for some ideas, but am not getting many ideas. Most of the responses I’ve found are related to Java.
My query:
CREATE TEMPORARY TABLE cte_most_recent_record
SELECT
leeds_new.leenk_ladder_history.member_id as member_id,
max(leeds_new.leenk_ladder_history.date_trigger_event) AS date_trigger_event_max
FROM leeds_new.leenk_ladder_history
WHERE leeds_new.leenk_ladder_history.ladder_change = 1 and leeds_new.leenk_ladder_history.ladder_advocacy is not NULL
group by leeds_new.leenk_ladder_history.member_id;
CREATE TEMPORARY TABLE cte_most_recent_record_date_ladder
select
lh.member_id,
lh.ladder_advocacy,
lh.date_trigger_event
from leeds_new.leenk_ladder_history as lh
inner join
cte_most_recent_record as cte_rr on lh.member_id = cte_rr.member_id
and lh.date_trigger_event = cte_rr.date_trigger_event_max
limit 100;
CREATE TEMPORARY TABLE cte_ladder_counts_before
select
ladder_advocacy,
count(ladder_advocacy) as ladder_counts_before
from cte_most_recent_record_date_ladder
where date_trigger_event < date('2018-01-01')
group by ladder_advocacy;
CREATE TEMPORARY TABLE cte_ladder_counts_after
select
ladder_advocacy,
count(ladder_advocacy) as ladder_counts_after
from cte_most_recent_record_date_ladder
where date_trigger_event > date('2018-01-01')
group by ladder_advocacy;
select
cte_ladder_counts_before.ladder_advocacy,
cte_ladder_counts_before.ladder_counts_before,
ladder_counts_after,
ladder_counts_before - ladder_counts_after
from cte_ladder_counts_before
inner join cte_ladder_counts_after on cte_ladder_counts_before.ladder_advocacy = cte_ladder_counts_after.ladder_advocacy;
drop table cte_most_recent_record;
drop table cte_most_recent_record_date_ladder;
drop table cte_ladder_counts_before;
drop table cte_ladder_counts_after;
The error:
Sorry, we encountered an error and were unable to complete your request.
Failed to execute connection with error: Can not issue data manipulation statements with executeQuery().
Error ID: 24721465
I believe that this has something to do with that I have multiple tables within the same query - because I can run the query with just one of the select statements? But I am not sure if there are other data studio things I should be aware of.
Thoughts?
I know it's a bit late for an answer, but just in case someone needs this in the future. I ran into the same issue today. And the answer is quite frustrating as it is easy to solve.
You're using a CREATE TEMPORARY TABLE sentence (as I was doing too). Then I realized that DataStudio can't process that sentence. (Apparently, it can't do multi-queries either).
So my workaround was to actually CREATE the table in my database, not as a temporary one. (effective but not clean at all)... and delete the CREATE TEMPORARY TABLE sentence in my query. worked like a charm but on the dark side, now I have an useless table in my database just to process that query.
Hope it helps, kind regards.

Using EXEC() AT [Linked Server] for Insert data from local server

let me first explain a little abot my setup before letting you know the issue Im dealing with:
I have two database servers: SQL 2008 and MySql. I have a procedure in SQL that first, deletes a table in MySql and then populates it with some data from the SQL itself. For both actions im using OPENQUERY. But, as you know, it doesnt know support large data. It becomes really slow eventhou for truncating the table in MySql (it was taking like 14 minutes to delete 60k rows... insane!).
So i found out i could use this syntax for truncating:
EXEC ('TRUNCATE TABLE table_name') AT LINKEDSERVER
But i havent been able to find the syntax for inserting the results of the SQL table to my MySql table thru this. It works correct when I insert static data, like this example:
EXEC ('INSERT INTO table_name (row1, row2) VALUES (value1, value2)') AT LINKEDSERVER
But I want to insert the results from a SQL, as I said, something like this:
EXEC ('INSERT INTO table_name (row1, row2) SELECT r1, r2 FROM SQL_DB.sql_table_name') AT LINKEDSERVER
I bet that i cannot do it because in that syntax, Im executing the exec in the MySql server and the SQL table doesnt exist there. So how can i referrence my SQL table inside the "EXEC() AT" syntax?
Thank you.
you have to use "OPENQUERY" to do this - see
https://learn.microsoft.com/de-de/sql/t-sql/functions/openquery-transact-sql?view=sql-server-ver15
You can also use this:
INSERT INTO [LinkedServer].Database.Schema.Table(Attributes)
From
Select (attributes) from Database.Schema.Table as TableAlias

How to update ms sql database after insert data on mysql database?

I have a database on mysql (request from applestore) and now I must rewrite one table to ms sql. It's easy to rewrtie old rows, but when new row appear on mysql I need get this to ms sql table, and I don't know how to connect this and do it. Someone can hel me?
Why don't you try with triggers??..you need to create a trigger which insert the same data in a table when it is inserted in another table.

MySQL to SQL Server select statement

I am converting mysql sprocs to SQL Server. I've come across a select statement in mysql that I don't quite understand what it's doing and my google-fu/so-fu has failed me. Here is the gist of it:
SELECT AccountType = dbo.functionToGetAccountType() FROM AccountLookup
I don't have the ability to debug the original mysql. I do know that the function only returns a single value.
Is the mysql statement assigning a default value to 'AccountType' in the event there are no rows in the AccountLookup table?
Thanks for your time.
The select statement is executing the function dbo.functionToGetAccountType() and aliasing the column as AccountType. It could be re-written as:
SELECT dbo.functionToGetAccountType() as AccountType
FROM AccountLookup