简体   繁体   English

如何在 Azure Synapse 无服务器 SQL 池中使用 CETAS 创建外部表时添加自动递增列?

[英]How to add auto incremented columns while creating External Tables using CETAS in Azure Synapse serverless SQL Pool?

In server-less SQL Pool, Identities are not supported, is there any better way to add an auto-incremented column while creating an external table using Select Statement.在无服务器 SQL 池中,不支持身份,有没有更好的方法在使用 Select 语句创建外部表时添加自动递增列。

    CREATE EXTERNAL TABLE temp.example_table
    WITH 
    (
        DATA_SOURCE = data_source_name,
        LOCATION = 'TempTables/exanple_table',
        FILE_FORMAT = parquet_file_format
    )
    AS 


    SELECT  name                                    AS user_name
         , code                                        AS user_code
      FROM schema.example_table
 

How can we add an auto-increment column along with the name and code column in external table?我们如何在外部表中添加自动增量列以及名称和代码列?

I want something like -我想要类似的东西 -

id ID user_name用户名 user_code用户代码
1 1 Indrajeet英德拉吉特 SinghI辛格
2 2 Himanshu喜满洲 RawatH拉瓦特
3 3 Akshay阿克谢 SharmaA夏尔马

Try ROW_NUMBER:尝试 ROW_NUMBER:


    CREATE EXTERNAL TABLE temp.example_table
    WITH 
    (
        DATA_SOURCE = data_source_name,
        LOCATION = 'TempTables/exanple_table',
        FILE_FORMAT = parquet_file_format
    )
    AS 


    SELECT  ROW_NUMBER() OVER (ORDER BY code) as id
         , name                                    AS user_name
         , code                                        AS user_code
      FROM schema.example_table

One warning.一警告。 If you run the same tomorrow it won't necessarily be the same id for Akshay.如果您明天运行相同的代码,则 Akshay 的 ID 不一定相同。 So this may not be appropriate except for a one-time load.因此,除了一次性加载之外,这可能不合适。

If stability cross days is important you might try HASHBYTES('MD5', code) as id .如果跨天的稳定性很重要,您可以尝试HASHBYTES('MD5', code) as id On a small table that should be unique.在一张应该是独一无二的小桌子上。 But on a large table you may have hash collisions and it not be unique.但在一张大桌子上,您可能会遇到 hash 冲突,而且它不是唯一的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Synapse Serverless SQL 中的大型表的 CETAS 超时 - CETAS times out for large tables in Synapse Serverless SQL 在 Azure Synapse 专用/无服务器 SQL 池中使用增量表 - Using Delta Tables in Azure Synapse Dedicated/Serverless SQL Pools 是否可以使用 Azure Synapse Serverless SQL 池过滤动态日期范围? - Is it possible to filter on a dynamic date range with an Azure Synapse Serverless SQL Pool? 如何在 Azure Synapse Serverless 池中为 Lake 数据库创建视图 - How to create view in Azure Synapse Serverless pool for a Lake Database 如何在 Synapse Analytics 无服务器 SQL 池中对行进行随机抽样? - How to do random sampling of rows in Synapse Analytics serverless SQL pool? Synapse Serverless Pool 使用 CETAS 将数据写回 ADLS Gen-2 >> 权限问题 - Synapse Server less Pool writing data back to ADLS Gen-2 using CETAS >> Permissions issue Azure 突触,SQL 池作为数据流中的源 - Azure synapse, SQL pool as a source in dataflow 如何使用动态 SQL 在 Azure Synapse 中的表列表上循环 SELECT 语句? - How to loop a SELECT statement on a list of tables in Azure Synapse using Dynamic SQL? 为 azure 突触分析创建外部表的问题 - problems in creating external table for azure synapse analytics 如何在SQL中为添加的行添加具有自动递增值的列? - How to add column with auto incremented value for added rows in SQL?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM