使用 Azure 数据工厂中的复制数据工具指定要复制的表的顺序以尊重外键
Specify order of tables to copy using the Copy Data tool in Azure Data Factory to respect foreign keys
Copy Data 工具让我可以 select 将要从源复制到目标的表,但这些表是按 字母顺序 顺序复制的.因为我定义了外键,所以这行不通。我想手动更改订单。
不幸的是,据我所知,ADF copy activity SQL DB connector 默认情况下只能传输 tables order.It 无法扫描您的约束策略并以最佳顺序执行。
所以,恐怕你必须弄清楚你的约束策略是如何设置的并做出正确的顺序manually.After获取table名称排序列表,创建副本activity 一个接一个 table。
当然,不用担心这个 part.Every 元素可以由 ADF SDK or Powershell script 创建。您需要做的就是循环列表并将其传递到代码片段或 script.Only table 名称需要根据 activity 更改。
这是一个将数据从一个数据库复制到另一个数据库的简单管道 - 它有一个 ForEach,其中有 2 个活动。它复制每个 table,然后 运行 在每个 table 之后复制一个存储过程。 table 中的列名相同。它有一个名为 tableMapping 的变量,它是一个 json 数组,定义了 'from' 和 'to' table 名称,因为它们可以不同。 ForEach 具有此设置 "batchCount": 1,因此它 运行 一次一个。在我刚才的测试中,它处理变量 tableMapping 中序列中的 tables。如果您不指定 batchCount = 1,那么它将 运行 它们并行。
{
"name": "TowWorks to Azure SQL DB",
"properties": {
"activities": [
{
"name": "ForEach1",
"type": "ForEach",
"dependsOn": [],
"userProperties": [],
"typeProperties": {
"items": {
"value": "@variables('tableMapping')",
"type": "Expression"
},
"batchCount": 1,
"activities": [
{
"name": "Copy from BI to Azure",
"type": "Copy",
"dependsOn": [],
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "SqlServerSource",
"queryTimeout": "02:00:00"
},
"sink": {
"type": "AzureSqlSink",
"preCopyScript": {
"value": "@{concat('truncate table raw.', item().to)}",
"type": "Expression"
},
"disableMetricsCollection": false
},
"enableStaging": false
},
"inputs": [
{
"referenceName": "BI_TW_Raw_NoTable",
"type": "DatasetReference",
"parameters": {
"tableName": {
"value": "@item().from",
"type": "Expression"
}
}
}
],
"outputs": [
{
"referenceName": "TW_Azure_DB_noTable",
"type": "DatasetReference",
"parameters": {
"schema": "raw",
"table": {
"value": "@item().to",
"type": "Expression"
}
}
}
]
},
{
"name": "Stored Procedure1",
"type": "SqlServerStoredProcedure",
"dependsOn": [
{
"activity": "Copy from BI to Azure",
"dependencyConditions": [
"Succeeded"
]
}
],
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"storedProcedureName": {
"value": "@concat('raw.Update', item().to)",
"type": "Expression"
}
},
"linkedServiceName": {
"referenceName": "TowWorksAzureSqlDB",
"type": "LinkedServiceReference"
}
}
]
}
}
],
"variables": {
"tableMapping": {
"type": "Array",
"defaultValue": [
{
"from": "WORK_TASKS",
"to": "WorkTask"
},
{
"from": "Invoice",
"to": "Invoice"
},
{
"from": "ASSET",
"to": "Asset"
},
{
"from": "InvoiceDistribution",
"to": "InvoiceDistribution"
},
{
"from": "InvoiceEvent",
"to": "InvoiceEvent"
},
{
"from": "InvoiceTransaction",
"to": "InvoiceTransaction"
},
{
"from": "LOGISTICS_ORDERS",
"to": "LogisticOrder"
},
{
"from": "LOGISTICS_ORDERS_LINE_ITEMS",
"to": "LogisticOrderLineItem"
},
{
"from": "WORK_ORDERS",
"to": "WorkOrder"
},
{
"from": "WORK_ORDERS_STATUSES",
"to": "WorkOrderStatus"
}
]
},
"from": {
"type": "String"
},
"to": {
"type": "String"
}
},
"folder": {
"name": "TowWorks"
},
"annotations": []
}
}
Copy Data 工具让我可以 select 将要从源复制到目标的表,但这些表是按 字母顺序 顺序复制的.因为我定义了外键,所以这行不通。我想手动更改订单。
不幸的是,据我所知,ADF copy activity SQL DB connector 默认情况下只能传输 tables order.It 无法扫描您的约束策略并以最佳顺序执行。
所以,恐怕你必须弄清楚你的约束策略是如何设置的并做出正确的顺序manually.After获取table名称排序列表,创建副本activity 一个接一个 table。
当然,不用担心这个 part.Every 元素可以由 ADF SDK or Powershell script 创建。您需要做的就是循环列表并将其传递到代码片段或 script.Only table 名称需要根据 activity 更改。
这是一个将数据从一个数据库复制到另一个数据库的简单管道 - 它有一个 ForEach,其中有 2 个活动。它复制每个 table,然后 运行 在每个 table 之后复制一个存储过程。 table 中的列名相同。它有一个名为 tableMapping 的变量,它是一个 json 数组,定义了 'from' 和 'to' table 名称,因为它们可以不同。 ForEach 具有此设置 "batchCount": 1,因此它 运行 一次一个。在我刚才的测试中,它处理变量 tableMapping 中序列中的 tables。如果您不指定 batchCount = 1,那么它将 运行 它们并行。
{
"name": "TowWorks to Azure SQL DB",
"properties": {
"activities": [
{
"name": "ForEach1",
"type": "ForEach",
"dependsOn": [],
"userProperties": [],
"typeProperties": {
"items": {
"value": "@variables('tableMapping')",
"type": "Expression"
},
"batchCount": 1,
"activities": [
{
"name": "Copy from BI to Azure",
"type": "Copy",
"dependsOn": [],
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "SqlServerSource",
"queryTimeout": "02:00:00"
},
"sink": {
"type": "AzureSqlSink",
"preCopyScript": {
"value": "@{concat('truncate table raw.', item().to)}",
"type": "Expression"
},
"disableMetricsCollection": false
},
"enableStaging": false
},
"inputs": [
{
"referenceName": "BI_TW_Raw_NoTable",
"type": "DatasetReference",
"parameters": {
"tableName": {
"value": "@item().from",
"type": "Expression"
}
}
}
],
"outputs": [
{
"referenceName": "TW_Azure_DB_noTable",
"type": "DatasetReference",
"parameters": {
"schema": "raw",
"table": {
"value": "@item().to",
"type": "Expression"
}
}
}
]
},
{
"name": "Stored Procedure1",
"type": "SqlServerStoredProcedure",
"dependsOn": [
{
"activity": "Copy from BI to Azure",
"dependencyConditions": [
"Succeeded"
]
}
],
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"storedProcedureName": {
"value": "@concat('raw.Update', item().to)",
"type": "Expression"
}
},
"linkedServiceName": {
"referenceName": "TowWorksAzureSqlDB",
"type": "LinkedServiceReference"
}
}
]
}
}
],
"variables": {
"tableMapping": {
"type": "Array",
"defaultValue": [
{
"from": "WORK_TASKS",
"to": "WorkTask"
},
{
"from": "Invoice",
"to": "Invoice"
},
{
"from": "ASSET",
"to": "Asset"
},
{
"from": "InvoiceDistribution",
"to": "InvoiceDistribution"
},
{
"from": "InvoiceEvent",
"to": "InvoiceEvent"
},
{
"from": "InvoiceTransaction",
"to": "InvoiceTransaction"
},
{
"from": "LOGISTICS_ORDERS",
"to": "LogisticOrder"
},
{
"from": "LOGISTICS_ORDERS_LINE_ITEMS",
"to": "LogisticOrderLineItem"
},
{
"from": "WORK_ORDERS",
"to": "WorkOrder"
},
{
"from": "WORK_ORDERS_STATUSES",
"to": "WorkOrderStatus"
}
]
},
"from": {
"type": "String"
},
"to": {
"type": "String"
}
},
"folder": {
"name": "TowWorks"
},
"annotations": []
}
}