Is there the possibility of data loss while converting text data types to nvarchar(max)?

Asked

Viewed 42 times

1

I have a legacy database in production with data stored with the type text but there was a 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 text be passed over.

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

Thank you

  • could post the code?

  • I’m not DBA, so please don’t be alarmed by my approach, but it would be a direct change from one field type to another, something like : ALTER TABLE t1 ALTER COLUMN c NVARCHAR (MAX);

  • Does it need to be nvarchar? Can’t it just be varchar? Beware that the type of nvarchar data takes up twice as much space.

1 answer

1

If your database version is smaller than SQL Server 2019, use NVARCHAR(max) to minimize conversion problems. Basic implementation of both types TEXT and VARCHAR(max) is practically the same but with NVARCHAR(max) you a data type big enough to support this change.

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

This will transform your spine TEXT in a column NVARCHAR(max) without any data loss.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.