[英]How to execute a SQL query in Azure Data Factory
I create a pipeline in ADF for performing copy activity.我在 ADF 中创建了一个管道来执行复制活动。 My source database is Azure SQL database and Sink is Azure Blob.I want to execute an SQL Query in ADF to delete data from source once data is copied to blob.
我的源数据库是 Azure SQL 数据库,Sink 是 Azure Blob。一旦数据复制到 Blob,我想在 ADF 中执行 SQL 查询以从源中删除数据。 I am not allowed to use copy or lookup to execute query.Is their any custom way to do this.I need to create a view and have to do some activity.Please help
我不允许使用复制或查找来执行查询。他们是否有任何自定义方式来执行此操作。我需要创建一个视图并且必须执行一些活动。请帮忙
You can also use the built-in stored procedure sp_executesql
, which allows you to provide a random SQL statement as parameter.您还可以使用内置存储过程
sp_executesql
,它允许您提供随机 SQL 语句作为参数。 That way you don't have to implement your own stored procedure.这样您就不必实现自己的存储过程。
See more information about this stored procedure on sp_executesql (Transact-SQL) .在sp_executesql (Transact-SQL)上查看有关此存储过程的更多信息。
If you are using data mapping flows, there is a new activity to execute custom SQL scripts:如果您使用数据映射流,则有一个新活动来执行自定义 SQL 脚本:
In a regular pipeline, you probably have to resort to using the Stored Procedure activity:在常规管道中,您可能不得不求助于使用存储过程活动:
You would have to write the delete logic in the SP, and then invoke the SP from Data Factory.您必须在 SP 中编写删除逻辑,然后从数据工厂调用 SP。
You can write a stored procedure for deleting the data from source table and call that stored procedure in "Stored procedure" activity after copy activity.您可以编写一个用于从源表中删除数据的存储过程,并在复制活动之后在“存储过程”活动中调用该存储过程。
Your data flow will look like:您的数据流将如下所示:
COPY ACTIVITY -----> STORED PROCEDURE ACTIVITY
I also faced this problem and I could find 3 simple workarounds: 我也遇到了这个问题,我可以找到3个简单的解决方法:
More details if you're interested: https://martinistibi.wordpress.com/2019/11/06/azure-data-factory-execute-sql-task/ 如果您有兴趣, 请查看更多详细信息: https : //martinistibi.wordpress.com/2019/11/06/azure-data-factory-execute-sql-task/
They have rolled out the script activity他们推出了脚本活动
The script task can be used for the following purposes:脚本任务可用于以下目的:
Truncate a table or view in preparation for inserting data.截断表或视图以准备插入数据。 Create, alter, and drop database objects such as tables and views.
创建、更改和删除数据库对象,例如表和视图。 Re-create fact and dimension tables before loading data into them.
在将数据加载到其中之前重新创建事实表和维度表。 Run stored procedures.
运行存储过程。 If the SQL statement invokes a stored procedure that returns results from a temporary table, use the WITH RESULT SETS option to define metadata for the result set.
如果 SQL 语句调用从临时表返回结果的存储过程,请使用 WITH RESULT SETS 选项为结果集定义元数据。 Save the rowset returned from a query as activity output for downstream consumption.
将查询返回的行集保存为活动 output 以供下游使用。
Script task is present under General tab of Activities.脚本任务位于活动的常规选项卡下。
Ref 1 https://learn.microsoft.com/en-us/azure/data-factory/transform-data-using-script参考 1 https://learn.microsoft.com/en-us/azure/data-factory/transform-data-using-script
Ref 2 https://techcommunity.microsoft.com/t5/azure-data-factory-blog/execute-sql-statements-using-the-new-script-activity-in-azure/ba-p/3239969参考 2 https://techcommunity.microsoft.com/t5/azure-data-factory-blog/execute-sql-statements-using-the-new-script-activity-in-azure/ba-p/3239969
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.