What is the best way to store a large amount of text in a SQL server table?

前端 未结 8 463
日久生厌
日久生厌 2020-12-15 15:19

What is the best way to store a large amount of text in a table in SQL server?

Is varchar(max) reliable?

相关标签:
8条回答
  • 2020-12-15 15:39

    I like using VARCHAR(MAX) (or actually NVARCHAR) because it works like a standard VARCHAR field. Since it's introduction, I use it rather than TEXT fields whenever possible.

    0 讨论(0)
  • 2020-12-15 15:40

    In SQL 2005 and higher, VARCHAR(MAX) is indeed the preferred method. The TEXT type is still available, but primarily for backward compatibility with SQL 2000 and lower.

    0 讨论(0)
  • 2020-12-15 15:41

    Varchar(max) is available only in SQL 2005 or later. This will store up to 2GB and can be treated as a regular varchar. Before SQL 2005, use the "text" type.

    0 讨论(0)
  • 2020-12-15 15:43

    Use nvarchar(max) to store the whole chat conversation thread in a single record. Each individual text message (or block) is identified in the content text by inserting markers.

    Example:

    {{UserId: Date and time}}<Chat Text>. 
    

    On display time UI should be intelligent enough to understand this markers and display it correctly. This way one record should suffice for a single conversation as long as size limit is not reached.

    0 讨论(0)
  • 2020-12-15 15:44

    It is better to save them as .txt file to server and save the file path to your database.

    0 讨论(0)
  • 2020-12-15 15:45

    In a BLOB

    BLOBs are very large variable binary or character data, typically documents (.txt, .doc) and pictures (.jpeg, .gif, .bmp), which can be stored in a database. In SQL Server, BLOBs can be text, ntext, or image data type, you can use the text type

    text

    Variable-length non-Unicode data, stored in the code page of the server, with a maximum length of 231 - 1 (2,147,483,647) characters.

    0 讨论(0)
提交回复
热议问题