简体   繁体   English

如何在 Azure 数据工厂中执行 SQL 查询

[英]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个简单的解决方法:

  • use a stored procedure and then execute it directly in ADF 使用存储过程,然后直接在ADF中执行
  • use sp_executesql and put in your query as a parameter 使用sp_executesql并将查询作为参数放入
  • use the LookUp activity even for UPDATE / DELETE / INSERT 即使对UPDATE / DELETE / INSERT也使用LookUp活动

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.

相关问题 Azure 数据工厂无法执行复制数据任务到 SQL 服务器 - Azure Data Factory fails to execute copy data task to SQL Server 如何提高在 Azure 数据工厂中执行日志存储过程的时间? - How to improve time to execute logging stored procedure in Azure Data Factory? 有没有办法从 Azure 数据工厂内部编写 SQL 查询? - Is there a way to author a SQL query from inside Azure Data Factory? 如何在 Azure 数据工厂上使用 Query If Else Condition? - How to use Query If Else Condition on Azure Data Factory? 是否可以在 Azure 托管实例上将数据工厂管道作为 SQL 代理作业中的一个步骤执行? - Is it possible to execute a Data Factory Pipeline as a step in a SQL Agent Job on Azure Managed Instance? 从cosmos db查询特定的时间范围数据,并通过azure数据工厂将其存储在sql数据库中 - Query a specific time range data from cosmos db and store it in sql database via azure data factory 源选项中的 Azure 数据工厂递归查询 - Azure Data Factory Recursive Query in source option 如何执行此SQL查询 - How to execute this SQL Query 在Azure SQL数据仓库中执行SQL脚本 - Execute SQL script in an Azure SQL Data Warehouse Azure数据工厂-Azure SQL Server目标架构 - Azure Data Factory - Azure SQL Server Destination Schema
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM