Accommodate Column that contains special characters without existing data loss ?

techresearch7777777 1,841 Reputation points
2024-02-06T18:11:26.3133333+00:00

Hello, within SQL Server 2019 there is a Column within a Table currently set as varchar(1000).

When data is loaded into this Column we noticed it sometimes contains special characters which in one particular record for this Column had 1000 characters but size was actually slightly larger around 1040 Bytes (not having the 1 to 1 character to byte ratio).

Realize probably will need to use some type of Unicode method.

Will simply changing that Column to nvarchar(max) do it without existing data loss?

Or would leaving this Column as is varchar(1000) and changing/implementing its Collation be better?

Like mentioned definitely want to avoid data loss.

Thanks in advance.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,632 questions
{count} votes

Accepted answer
  1. Erland Sommarskog 109.6K Reputation points MVP
    2024-02-06T22:10:20.93+00:00

    Yes, you can alter your column from being varchar(1000) to be nvarchar(MAX) without data loss. Beware, though, that this is a size-of-data operation, so it can take some time if the table is big.

    You could also keep it as varchar but change the collation a UTF8 collation. Or may be you already have a UTF8 collation, since you talk about 1-to-1 character byte ratio? If that is the case, there is no reason to change collation or data type, since you already have full Unicode support. But you may want to increase the max length or make it varchar(MAX) in that case.


0 additional answers

Sort by: Most helpful

Your answer

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