Saving history in SQL Server 2008?

I'm going to store stories in the nvarchar (MAX) fields in SQL Server, but I know that the stories will be much longer than MAX allows, and what approach should I take? Should I split the story into several lines or do I need to skip using the database and use text files?

+4
source share
4 answers

I believe the confusion stems from a misunderstanding of the terms here.

nvarchar(n) is a data type where n can be a number from 1 to 1000. The number n in this case has a maximum of 4000, which adds up to 8000 bytes (2 bytes per character).

nvarchar(MAX) is a completely different data type - the MAX keyword is a literal, and it is not synonymous with any potential value n in my example above. Fields of this type have a maximum length of 2 ^ 31-1 characters or more than 1 billion, which is more than 2 billion bytes (2 bytes per character).

The same principles apply to varchar(n) and varchar(MAX) , except that each character can only be 1 byte, in which case the number of characters that can be stored is double. Whether this is only 1 byte depends on the sort, as Martin Smith notes in a comment!

+7
source

Save them in chapters.

This is not technical - it is pretty much impossible to guess 1 billion nvarchar characters (and nvarchar (max) is the new TEXT data type.

Loading and handling BUt will be painful.

Keep them as sections and keep the start / end page number for each chapter when it makes sense, so you can simplify things a bit.

By the way, you published that you think that it is 800 characters - it was NEVER. The limit will be 8000 bytes - if applicable - and it will be 4000 unicode characters.

+4
source

I would suggest that I look at database-oriented documents for something like this.

+2
source

Well, could you try to save as LONGTEXT (Mysql) or TEXT (MSSQL) (if you want to store objects that I think you can use BLOB) data type?

-3
source

Source: https://habr.com/ru/post/1390859/


All Articles