One of my coworkers is using SQL Server 2000 and is having a display issue where an XML column using data type ntext is displaying <Long Text>. I’m guessing that’s because the character length is too short (16), but it will not allow any changes.
When trying to alter the data type to varchar a warning appears. Will changing the datatype from ntext to varchar/nvarchar affect the data in the table?
Changing to
varcharwill potentially lose Unicode information, e.g.Results:
Changing to
nvarchar(<=4000)will potentially lose any data > 8000 bytes (4000 characters). Which may be okay if the designers chosentextbut never stored more than 4000 characters, but you should check that first:If this returns 0, you are probably safe to convert to
NVARCHAR(4000), but you will still not have an easy time modifying long text data using the SSMS tools (that is not what they’re for) and you still may have impacts to your applicationsYou may have applications or stored procedures that have special handling for
ntextcolumns, for example they may rely on functions likeREADTEXT,WRITETEXT,UPDATETEXTandTEXTPTR. You’ll want to search your codebase for these commands (here is one way to start looking at stored procedures that may contain these):Some chances there for false positives, hence “one way to start“.
But if I were in your shoes I would not just change the type.
Also, the 16 is not the character length (I can assure you you can fit more than 16 characters in that column).
textandntextdata is not stored on the data page (since it won’t fit on a single page), and the 16 bytes is the number of bytes that represent the pointer so that, when the page is read, it can tell SQL Server where, off-row, to go find the actual data.The real answer is to stop using the graphical tools in SSMS to look at (and especially to modify!) data. If you want to view the contents of an
ntextcolumn, you can select a substring, e.g.…or do this in an application. But don’t use
Open TableorEDIT TOP n ROWSas a spreadsheet.Another real answer is to get off of SQL Server 2000 already. In modern versions of SQL Server there is a much friendlier data type called
nvarchar(max).