views:

329

answers:

3

What is an effective datatype in SQL 2005 to store a comments field?

A: 

That depends on whether or not you limit the comment length. On SO, nvarchar(600) does it. On a blog, you probably want nvarchar(max).

Eric
Thanks, Eric
Csharp
`varchar(max)` or `nvarchar(max)` would be more appropriate than `text` on SQL Server 2005.
John Saunders
@John: You're right, I always forget that `text` was deprecated.
Eric
i think you always want a reasonable upper bound for any text field. nvarchar(max) on a public field opens your db for abuse.
Paul Sasik
@psasik: And if your reasonable upper bound is OVER 9000?!
Eric
+3  A: 

If the comment will always fit in 8000 chars then varchar(8000) (or nvarchar(4000)).

Otherwise a varchar(max)

Mitch Wheat
A: 

Apparently SQL 2005 only supports:

varchar(max) Variable-length non-Unicode data with a maximum length of 2^31 characters.

If you need unicode character strings,

nvarchar(max) Variable-length Unicode data with a maximum length of 2^30 characters.

text is also supported as a datatype. Use this site if you need more reference:

http://www.teratrax.com/sql_guide/data_types/sql_server_data_types.html

ninumedia
text will be deprecated in later versions and is nothing like as flexible as varchar(max).
gbn
This was mentioned for Eric's answer below too
gbn