views:

148

answers:

4

Possible Duplicate:
Are there any disadvantages to always using nvarchar(MAX)?

Is there a general downside by chosing 'ntext' as column type instead of a type that contains chars but with a limited max size like 'char' or 'varchar'?

I'm not sure whether a limited column size is applyable to all my colums. Therefore I would use 'ntext' for all columns containing text. Might this lead to problems in the future?

(I'm using Linq-To-SQL in a ASP.net Webforms application)

+5  A: 

NTEXT is being deprecated for a start, so you should use NVARCHAR(MAX) instead.

You should always try to use the smallest datatype possible for a column. If you do need to support more than 4000 characters in a field, then you'll need to use NVARCHAR(MAX). If you don't need to support more than 4000 characters, then use NVARCHAR(n).

I believe NTEXT would always be stored out of row, incurring an overhead when querying. NVARCHAR(MAX) can be stored in row if possible. If it can't fit in row, then SQL Server will push it off row. See this MSDN article.

Edit:
For NVARCHAR, the maximum supported explicit size is 4000. After that, you need to use MAX which takes you up to 2^31-1 bytes.
For VARCHAR, the maximum supported explicit size is 8000 before you need to switch to MAX.

AdaTheDev
Wow, I'm impressed. I've never heard of in/out of row storing. When do I get performance problems if I use a big number for MAX. Is NVARCHAR(4000) fine? Is there any difference to NVARCHAR(40000)? And what is the maximum char size for NVARCHAR?
citronas
+2  A: 

In addition to what AdaTheDev said, most of the standard T-SQL string functions do not work with NTEXT data types. You are much better off using VARCHAR(MAX) or NVARCHAR(MAX).

Randy Minder
+2  A: 

NVARCHAR furthermore is for widechars, e.g. non latin letters.

I had a stored procedure which ran with NVARCHAR parameters, when I changed it to use VARCHAR instead, I more than doubled the performance.

So if you know you won't need widechars in your columns, you're best of using VARCHAR.

and like the other answers says, don't use TEXT/NTEXT at all, they're deprecated.

Steffen
+2  A: 

You can never have an index on any text column because an index is limited to 900 bytes.

And ntext can't be indexed anyway, but there are still limitations on newer BLOB types too.

Do you plan on having only non-unique text columns? Or never plan to search them?

gbn
I plan to store input from the european charset. I could also safe them as unicode. The point is, that I do not know how long such strings will be in the future. My purpose is to find a good balance between database performance and scalability without the need to change the column type in the database itself. But I guess I won't need more than 4000 chars for this table. So the best choice would be varchar(400)?Nevertheless it would be good to know these things for the future for designing other tables.
citronas
If you go with varchar(4000), just remember to check in your application, that you never try to insert/update with longer strings than 4000 characters - otherwise you'll get an error somewhat like "string would be truncated".
Steffen