如何在 SQL 中创建临时表以用于多个 ADF 活动?

How to create temp tables in SQL to be used in several ADF activities?

我需要在我的 SQL 服务器中创建一个全局临时文件 table,同时执行 Azure 数据工厂管道。此 table 将用于多项活动。

我已经尝试了几种方法,包括一种使用针对 sys.sp_executesql SP 的存储过程 activity 和 CREATE TABLE 语句作为参数的方法。使用这种方法实际上创建了 table,但它在一秒钟后自动删除,我不明白为什么。

这是用于创建临时文件的脚本table:

CREATE TABLE ##tempGL
(
    GLAccount NVARCHAR(15),
    GLSubAccount NVARCHAR(15)
)

那么,我如何从 Azure 数据工厂管道 activity 创建一个 SQL 服务器临时 table 并在我删除它之前一直存在?

我自己也一直在为此苦苦挣扎。显然这是设计使然(请参阅下面来自 Microsoft 员工的引述)并且即使文档提到它是可能的,也无法使用 Azure 数据工厂实现此目的。

That is by design. We won’t keep connection between 2 activities. If you use a real table instead of temporary table. Then you will get the expected result. The suggestion is don’t used temporary table in ADF if the data need more than 1 activities to access.

https://github.com/MicrosoftDocs/azure-docs/issues/35449#issuecomment-517451867

发生这种情况的原因是会话在管道 activity 结束时被丢弃,这导致临时 table 也被丢弃。

Global temporary tables are automatically dropped when the session that created the table ends and all other tasks have stopped referencing them. The association between a task and a table is maintained only for the life of a single Transact-SQL statement. This means that a global temporary table is dropped at the completion of the last Transact-SQL statement that was actively referencing the table when the creating session ended.

https://docs.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql?view=sql-server-2017#temporary-tables

希望 Microsoft 能在某个时候修复此问题,并使在 Azure 数据工厂的活动中使用临时 table 成为可能。


我已在此处将此作为对 Azure 的建议 https://feedback.azure.com/forums/270578-data-factory/suggestions/38287108-persist-global-temporary-tables-between-activities

对于任何阅读本文可能想要他的功能的人,请为该建议投赞成票。