8

Possible Duplicate:
SQL Server Text type vs. varchar data type
Using varchar(MAX) vs TEXT on SQL Server

from this article, it looks like they both have the same size capacity: http://msdn.microsoft.com/en-us/library/ms143432.aspx

is that truly correct? what are the real differences?

i just migrated some data from oracle (clob and made it into a varchar(max), but it looks like it truncated some of the values anyway, should i use TEXT instead?

Thank you!

Community
  • 1
  • 1
Madam Zu Zu
  • 6,437
  • 19
  • 83
  • 129
  • 1
    TEXT is becoming depracated - http://andrewm-developmentnotes.blogspot.com/2011/03/text-type-deprecated-in-sql-server-2008.html – StuartLC Sep 12 '11 at 15:23
  • 1
    This thread has the answer you are looking for: http://stackoverflow.com/questions/564755/sql-server-text-type-vs-varchar-data-type – Icarus Sep 12 '11 at 15:23
  • http://stackoverflow.com/questions/834788/using-varcharmax-vs-text-on-sql-server – NullUserException Sep 12 '11 at 15:25
  • what code did you use to migrate the data? I think you have a problme with how you did it not what the datatype was. – HLGEM Sep 12 '11 at 17:56
  • Look at the link http://stackoverflow.com/q/28980502/1805776 – vicky Oct 18 '16 at 09:44

3 Answers3

13

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.

Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490
9

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)

Remus Rusanu
  • 288,378
  • 40
  • 442
  • 569
2

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?

billinkc
  • 59,250
  • 9
  • 102
  • 159