SQL 2008 - varchar(max) vs text data types [duplicate]

半世苍凉 提交于 2019-12-04 04:07:04

No, you should not use TEXT. For one, it has been deprecated since SQL Server 2005, and also you will find that many string operations do not work against it. Do not use TEXT, NTEXT or IMAGE at all - use VARCHAR(MAX), NVARCHAR(MAX) or VARBINARY(MAX) instead.

The legacy types (TEXT, NTEXT, IMAGE) are deprecated and support for them will be dropped in a future version of SQL Server.

There are significant differences in how you use them. The new MAX types support efficient updates with the .WRITE syntax. The legacy types have an arcane set of functions to achieve the same (TEXTPTR, UPDATETEXT, sp_invalidate_testptr).

The new MAX types can be used in functions like REPLACE or SUBSTRING, any function that accepts a VARCHAR(N) will also accept a VARCHAR(MAX).

The legacy types do not support implicit conversion which the MAX types support, see Data Type Conversions.

Certain engine features work with MAX types, but not with the legacy ones, eg. online operations (in SQL 11 they support tables with BLOBs)

The linked article only deals with space allocation. At a minimum, know that text, ntext and image data types will be removed from future releases of SQL Server so for new tables, use varchar(max), nvarchar(max) or varbinary(max).

Of equal importance would be how one interacts with those values. Would you rather use the standard column = 'really long value' or UPDATETEXT and other less common operations to work on a column because of the data type?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!