tags:

views:

994

answers:

6

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

Is varchar(max) reliable?

+10  A: 

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.

John Rudy
+3  A: 

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.

Stephen Wrighton
Very good point about NVARCHAR; my bad -- I should have mentioned that.
John Rudy
+2  A: 

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.

Paul Whelan
+1  A: 

According to the text found here, varbinary(max) is the way to go. You'll be able to store approximately 2GB of data.

Huuuze
+1  A: 

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.

Instantsoup
+1  A: 

Split the text into chunks that your database can actually handle. And, put the split up text in another table. Use the id from the text_chunk table as text_chunk_id in your original table. You might want another column in your table to keep text that fits within your largest text data type.

CREATE TABLE text_chunk (
     id NUMBER,
     chunk_sequence NUMBER,
     text BIGTEXT)
Mark Stock