I am going to store stories in nvarchar(MAX) fields in SQL Server, but I know the stories will be much longer than MAX allows, so what approach should I take? Should I split the story across multiple rows or should I skip using a database and use text files?
Share
I believe the confusion stems from a misunderstanding of terms here.
nvarchar(n)is a data type wherencan be a number from 1-4000. The numbernin this case has a max of 4000, which adds up to 8000 bytes (2 bytes per character).nvarchar(MAX)is a different data type altogether – the keywordMAXis a literal, and it is not a synonym for any potential value ofnin my example above. Fields of this type have a maximum length of 2^31-1 characters, or over 1 billion, which adds up to over 2 billion bytes (2 bytes per character).The same principles apply to
varchar(n)andvarchar(MAX), except each character may only be 1 byte, in which case the number of characters that can be stored is double. Whether it is only 1 byte depends on the collation, as Martin Smith notes in a comment!