How to store the value of a unicode source column greater than 16000 characters in a dedicated SQL pool table

Vivek Komarla Bhaskar 956 Reputation points
2024-02-16T13:40:00.2266667+00:00

Hi, There is a unicode source column that is variable in column length since it contains the body of a news article. Therefore, there is no limit to the length of this column. In order to utilize this information, I need to load it into a hash distribution type synapse table. The MAX data length cannot be set on a column of an nvarchar datatype in a hash distributed table. Is there a way to accomplish my requirements now?

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
{count} votes

1 answer

Sort by: Most helpful
  1. Vinodh247 40,141 Reputation points MVP Volunteer Moderator
    2024-02-17T10:57:03.78+00:00

    Hi Vivek Komarla Bhaskar,

    Thanks for reaching out to Microsoft Q&A.

    one way to set the MAX data length on a column of an nvarchar datatype in a hash distributed table is to use the NVARCHAR(MAX) data type. This data type can store up to 2 GB of Unicode string data..

    However, if the column has any constraint key like default, check, etc., you will need to drop the key constraint from the column before altering the size of the column and then add the constraint back to the column like below

    -- Drop the key constraint 
    ALTER TABLE table_name DROP CONSTRAINT constraint_name;
    
    -- Alter the column size 
    ALTER TABLE table_name ALTER COLUMN table_column NVARCHAR(MAX);
    
    -- Add the key constraint 
    ALTER TABLE table_name ADD CONSTRAINT constraint_name DEFAULT ('') FOR table_name;
    
    
    

    Alternatively, you can also use the VARBINARY(MAX) data type but I am not sure if that is supported in hash distributed table.

    Please 'Upvote'(Thumbs-up) and 'Accept' as an answer if the reply was helpful. This will benefit other community members who face the same issue.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.