Search code examples
sqlsql-serversql-updatentext

SQL Server NText field limited to 43,679 characters?


I working with SQL Server data base in order to store very long Unicode string. The field is from type 'ntext', which theoretically should be limit to 2^30 Unicode characters.

From MSDN documentation:

ntext

Variable-length Unicode data with a maximum string length of 2^30 - 1 (1,073,741,823) bytes. Storage size, in bytes, is two times the string length that is entered. The ISO synonym for ntext is national text.

I'm made this test:

  1. Generate 50,000 characters string.

  2. Run an Update SQL statement

    UPDATE [table] SET Response='... 50,000 character string...' WHERE ID='593BCBC0-EC1E-4850-93B0-3A9A9EB83123'

  3. Check the result - what actually stored in the field at the end.

The result was that the field [Response] contain only 43,679 characters. All the characters at the end of the string was thrown out.

Why this happens? How I can fix this?

If this is really the capacity limit of this data type (ntext), which another data type can store longer Unicode string?


Solution

  • Based on what I've seen, you may just only be able to copy 43679 characters. It is storing all the characters, they're in the db(check this with Select Len(Reponse) From [table] Where... to verify this), and SSMS has problem copying more than when you go to look at the full data.