[英]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.