数据工厂复制到临时 table

Data factory Copy to temporary table

我正在尝试遵循 MS 提供的关于如何使用数据工厂将批量数据复制到 Azure sql 中的简单最佳实践说明:

Best Practice

"方案一:当你有大量数据需要copy时,使用下面的方式进行upsert:

首先,使用临时 table 通过副本 activity 批量加载所有记录。由于不记录针对临时 table 的操作,因此您可以在几秒钟内加载数百万条记录。 ... 例如,##UpsertTempTable,作为数据集中的 table 名称。 “

我已按照这些说明进行操作,但未能复制数据。如果我使用真实 table 而不是临时 table 就没问题。真正的 table 即时创建并且数据导入成功

这是数据集JSON

{
"name": "UserTempTable",
"properties": {
    "linkedServiceName": {
        "referenceName": "AzureSqlDatabase1",
        "type": "LinkedServiceReference"
    },
    "annotations": [],
    "type": "AzureSqlTable",
    "schema": [],
    "typeProperties": {
        "table": "usertemptable"
    }
},
"type": "Microsoft.DataFactory/factories/datasets"
}

如果我将 "usertemptable" 替换为“##usertemptable”

它失败了

有什么想法吗?

数据工厂不支持自动创建临时文件 table。我们不能将“##usertemptable”设置为 table 名称:

错误:

{
    "errorCode": "2200",
    "message": "ErrorCode=SqlOperationFailed,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=A database operation failed. Please search error to get more details.,Source=Microsoft.DataTransfer.ClientLibrary,''Type=System.InvalidOperationException,Message=Cannot access destination table '[dbo].[##temptest]'.,Source=System.Data,''Type=System.Data.SqlClient.SqlException,Message=Invalid object name '##temptest'.,Source=.Net SqlClient Data Provider,SqlErrorNumber=208,Class=16,ErrorCode=-2146232060,State=0,Errors=[{Class=16,Number=208,State=0,Message=Invalid object name '##temptest'.,},],'",
    "failureType": "UserError",
    "target": "Copy data1",
    "details": []
}

对于 Azure SQL 数据库,临时 table 在 TempDB 中,但我们无法在系统数据库中看到和访问它。我们也不能选择临时 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.

你可以参考这个link。给你很多帮助和建议。

您也可以参考这篇博客:Using global temporary table in copy activity not working。 Microsoft MSFT 为您提供了另一种方法,您可以使用存储过程将数据插入临时 table。

一些注意事项:创建临时 table 时不要关闭 SQL 连接会话。

如果所有这些都不适合您,您可能需要考虑为什么坚持使用临时 table 因为 Copy Active 具有良好的数据复制性能。最终的选择可能是使用真正的 table 而不是临时的 table.

希望对您有所帮助。

sql 中提供了新功能,因此不用创建临时文件 table,而是使用 table 类型。它也很容易实现。