简体   繁体   English

更新接收器表中的值-azure 数据工厂

[英]updating a value in sink table -azure data factory

I'm trying to move data from Mariadb to Azure SQL database lets assume that the table in the Azure SQL contains the following data: I'm trying to move data from Mariadb to Azure SQL database lets assume that the table in the Azure SQL contains the following data:

id ID state state insert time插入时间 updated value更新值
1 1 100 100 2022-01-01 14:30:00 2022-01-01 14:30:00 yes是的
2 2 100 100 2022-01-01 14:30:00 2022-01-01 14:30:00 yes是的
10 10 200 200 2022-01-01 14:30:00 2022-01-01 14:30:00 yes是的

Lets assume I retrieved data from the marinade and it returned the following results:假设我从腌料中检索数据并返回以下结果:

id ID state state insert time插入时间 updated value更新值
1 1 300 300 2022-01-01 15:30:00 2022-01-01 15:30:00 yes是的
2 2 200 200 2022-01-01 15:30:00 2022-01-01 15:30:00 yes是的
12 12 100 100 2022-01-01 15:30:00 2022-01-01 15:30:00 yes是的

What I want to do is to check if the query results from the Maria returns ids that are exists in the azure SQL if it exists it updates the value of "updated value" column in the azure SQL to No then insert the query results of the Mariadb so the table should look like this: What I want to do is to check if the query results from the Maria returns ids that are exists in the azure SQL if it exists it updates the value of "updated value" column in the azure SQL to No then insert the query results of the Mariadb 所以表格应该是这样的:

id ID state state insert time插入时间 updated value更新值
1 1 100 100 2022-01-01 14:30:00 2022-01-01 14:30:00 NO
2 2 100 100 2022-01-01 14:30:00 2022-01-01 14:30:00 NO
10 10 200 200 2022-01-01 14:30:00 2022-01-01 14:30:00 yes是的
1 1 300 300 2022-01-01 15:30:00 2022-01-01 15:30:00 yes是的
2 2 200 200 2022-01-01 15:30:00 2022-01-01 15:30:00 yes是的
12 12 100 100 2022-01-01 15:30:00 2022-01-01 15:30:00 yes是的

Most of the things I found on the internet are performing upset but I want to keep the old data in order to have insights on the states per a given time.我在互联网上发现的大多数事情都表现不佳,但我想保留旧数据,以便了解特定时间的状态。 So how can I implement such a thing那么我该如何实现这样的事情

After you insert the new data you should be able to update the existing records with something like this (not tested) assuming you have the new 'insert time'.插入新数据后,假设您有新的“插入时间”,您应该能够使用类似这样的内容(未经测试)更新现有记录。

update yourTable 
set [updated value] = 'NO' 
where id in (select id from yourTable where [insert time] = @NewInsertTIme)

where &NewInsertTime is the new 'insert time' (2022-01-01 15:30:00 in your example).其中 &NewInsertTime 是新的“插入时间”(在您的示例中为 2022-01-01 15:30:00)。 You can use the Script Activity to run the code or put it in a stored procedure and use the Stored Procedure Activity to call it.您可以使用脚本活动来运行代码或将其放入存储过程中并使用存储过程活动来调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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