英文:
Azure Data Factory Expression If else auto create and truncate table
问题
I will only provide translations for the non-code portions you've mentioned. Here they are:
我只会提供非代码部分的翻译。以下是翻译:
-
"I'm just quite new in ADF so I would like to know how I can change the following expression to auto-create a table in my sink table."
"我在ADF中还比较新,所以我想知道如何将以下表达式更改为在我的接收器表中自动创建表格。" -
"This expression can truncate the existing SQL Schema and SQL table. But when I need to make a new schema and table, the Copy Data Activity failed. What change do I need to make in the current expression?"
"这个表达式可以截断现有的SQL模式和SQL表格。但是当我需要创建新的模式和表格时,复制数据活动失败了。我需要在当前表达式中做出什么改变?" -
"This is the current config of my Sink page."
"这是我的接收器页面的当前配置。"
英文:
im just quite new in ADF so i would like to know how i can change the folowing expression to auto create table in my sink table.
This is the current expression:
This expression can truncate the existing SQL Schema and SQL table. But when i need to make new schema and table the Copy Data Activity failed. What change do i need to make in the current expression?
**
@{if(and(not(empty(pipeline().parameters.SQLTargetSchemaName)),
not(empty(pipeline().parameters.SQLTargetTableName))),
concat('truncate table [', pipeline().parameters.SQLTargetSchemaName, '].[', pipeline().parameters.SQLTargetTableName, ']'), '')
}
**
This is the current config of my Sink page :
答案1
得分: 1
在预复制脚本中使用以下查询以满足您的需求。
IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '@{pipeline().parameters.tablename}')
begin
TRUNCATE table [@{pipeline().parameters.schema}].[@{pipeline().parameters.tablename}];
end
并确保在复制活动的接收器中选择“自动创建表”。
这里,我们的预复制脚本检查表是否存在,如果存在,则截断表。如果不存在,则不执行任何操作。
“自动创建表”只有在模式中不存在表时才创建新表,如果已经存在,则不执行任何操作。
在这里,我的表已经存在一行数据,因此它截断了表并插入了来自源的值。
英文:
Use the below query in the pre-copy script to achieve your requirement.
IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '@{pipeline().parameters.tablename}')
begin
TRUNCATE table [@{pipeline().parameters.schema}].[@{pipeline().parameters.tablename}];
end
And make sure you select the Auto create table
in the copy activity sink.
Here, our pre-copy script checks whether the table exists or not, if exists it truncates the table. If not exists, it won't do anything.
The Auto create table
creates new table only when the table is not exists in the schema, if it already exists it won't do anything.
Here, my table already exists with one row, so it truncated the table and inserted values from the source.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论