Azure数据工厂表达式自动创建和截断表

huangapple go评论52阅读模式
英文:

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:

我只会提供非代码部分的翻译。以下是翻译:

  1. "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中还比较新,所以我想知道如何将以下表达式更改为在我的接收器表中自动创建表格。"

  2. "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表格。但是当我需要创建新的模式和表格时,复制数据活动失败了。我需要在当前表达式中做出什么改变?"

  3. "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 :

Azure数据工厂表达式自动创建和截断表

答案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.

Azure数据工厂表达式自动创建和截断表

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.

Azure数据工厂表达式自动创建和截断表

huangapple
  • 本文由 发表于 2023年5月25日 23:04:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76333768.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定