我正在使用 ADF 加载 SQL Server 表,插入结束后,我必须使用以下方法进行少量操作
触发器(插入后)- 失败,SQL Server 无法检测到我使用 ADF 推送的插入记录。
**Seems to be a bug**
。使用用户定义的表类型的存储过程 - 出现错误
Error Number '156'. Error message from database execution : Incorrect syntax near the keyword 'select'. Must declare the table variable "@a".
我创建了以下管道
{
"name": "CopyPipeline-xxx",
"properties": {
"activities": [
{
"type": "Copy",
"typeProperties": {
"source": {
"type": "AzureDataLakeStoreSource",
"recursive": false
},
"sink": {
"type": "SqlSink",
"sqlWriterStoredProcedureName": "sp_xxx",
"storedProcedureParameters": {
"stringProductData": {
"value": "str1"
}
},
"writeBatchSize": 0,
"writeBatchTimeout": "00:00:00"
},
"translator": {
"type": "TabularTranslator",
"columnMappings": "col1:col1,col2:col2"
}
},
"inputs": [
{
"name": "InputDataset-3jg"
}
],
"outputs": [
{
"name": "OutputDataset-3jg"
}
],
"policy": {
"timeout": "1.00:00:00",
"concurrency": 1,
"executionPriorityOrder": "NewestFirst",
"style": "StartOfInterval",
"retry": 3,
"longRetry": 0,
"longRetryInterval": "00:00:00"
},
"scheduler": {
"frequency": "Hour",
"interval": 8
},
"name": "Activity-0-xxx_csv->[dbo]_[xxx_staging]"
}
],
"start": "2017-01-09T21:48:53.348Z",
"end": "2099-12-30T18:30:00Z",
"isPaused": false,
"hubName": "hub",
"pipelineMode": "Scheduled"
}
}
并使用下面的存储过程
create procedure [dbo].[sp_xxx] @xxx1 [dbo].[ut_xxx] READONLY, @str1 varchar(100) AS
MERGE xxx_dummy AS a
USING @xxx1 AS b
ON (a.col1 = b.col1)
WHEN NOT MATCHED
THEN INSERT(col1, col2)
VALUES(b.col1, b.col2)
WHEN MATCHED
THEN UPDATE SET a.col2 = b.col2;
请帮我解决这个问题。
最佳答案
我可以重现您的第一个错误。使用 Azure 数据工厂 (ADF) 插入 SQL Server 表似乎使用批量插入方法(类似于 BULK INSERT、bcp、SSIS 等),并且默认情况下这些方法不会触发触发器:
insert bulk [dbo].[testADF] ([col1] Int, [col2] Int, [col3] Int, [col4] Int)
with (TABLOCK, CHECK_CONSTRAINTS)
对于 bcp,BULK INSERT
有一个标志可以更改为“触发触发器”,但似乎无法更改 ADF 的此设置。作为解决方法,请将逻辑从触发器移至存储过程中。
如果您认为此标志很重要,请考虑创建 feedback item .
关于azure - 使用 ADF 调用存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41569145/