Is there a possibility of data loss when converting text data types to nvarchar (max)?

I have a legacy database in production with data stored with Type text but there was the need to convert them to nvarchar(max) and by chance I saw that this was already a recommendation from Microsoft due to the issue of Type text being dropped.

The question is whether a direct conversion between types would be a better option, since it is not clear if there is any problem in this process, such as differences encoding incompatibility or data loss ?

Thank you

Author: Vinicius Dutra, 2020-07-28

1 answers

If your database version is smaller than SQL Server 2019, use NVARCHAR(max) to minimize conversion issues. The basic implementation of both types TEXT and VARCHAR(max) is pretty much the same but with NVARCHAR(max) you get a data type large enough to support this change.

ALTER TABLE <table_name> ALTER COLUMN <column_name> NVARCHAR(MAX)

This will turn your column TEXT into a column NVARCHAR(max) without any data loss.

 1
Author: Rodrigo Nascentes, 2020-08-17 17:40:35