Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>TEXT</code> is used for large pieces of string data. If the length of the field exceeed a certain threshold, the text is stored out of row.</p> <p><code>VARCHAR</code> is always stored in row and has a limit of <em>8000</em> characters. If you try to create a <code>VARCHAR(x)</code>, where <em>x > 8000</em>, you get an error:</p> <blockquote> <p>Server: Msg 131, Level 15, State 3, Line 1</p> <p>The size () given to the type ‘varchar’ exceeds the maximum allowed for any data type (8000) </p> </blockquote> <p>These length limitations do not concern <code>VARCHAR(MAX)</code> in <em>SQL Server 2005</em>, which may be stored out of row, just like <code>TEXT</code>.</p> <p>Note that <code>MAX</code> is not a kind of constant here, <code>VARCHAR</code> and <code>VARCHAR(MAX)</code> are very different types, the latter being very close to <code>TEXT</code>.</p> <p>In prior versions of <em>SQL Server</em> you could not access the <code>TEXT</code> directly, you only could get a <code>TEXTPTR</code> and use it in <code>READTEXT</code> and <code>WRITETEXT</code> functions.</p> <p>In <em>SQL Server 2005</em> you can directly access <code>TEXT</code> columns (though you still need an explicit cast to <code>VARCHAR</code> to assign a value for them).</p> <p><code>TEXT</code> is good:</p> <ul> <li>If you need to store large texts in your database</li> <li>If you do not search on the value of the column</li> <li>If you select this column rarely and do not join on it.</li> </ul> <p><code>VARCHAR</code> is good:</p> <ul> <li>If you store little strings</li> <li>If you search on the string value</li> <li>If you always select it or use it in joins.</li> </ul> <p>By <em>selecting</em> here I mean issuing any queries that return the value of the column.</p> <p>By <em>searching</em> here I mean issuing any queries whose result depends on the value of the <code>TEXT</code> or <code>VARCHAR</code> column. This includes using it in any <code>JOIN</code> or <code>WHERE</code> condition.</p> <p>As the <code>TEXT</code> is stored out of row, the queries not involving the <code>TEXT</code> column are usually faster.</p> <p>Some examples of what <code>TEXT</code> is good for:</p> <ul> <li>Blog comments</li> <li>Wiki pages</li> <li>Code source</li> </ul> <p>Some examples of what <code>VARCHAR</code> is good for:</p> <ul> <li>Usernames</li> <li>Page titles</li> <li>Filenames</li> </ul> <p>As a rule of thumb, if you ever need you text value to exceed <em>200</em> characters <strong>AND</strong> do not use join on this column, use <code>TEXT</code>.</p> <p>Otherwise use <code>VARCHAR</code>.</p> <p><em>P.S.</em> The same applies to <code>UNICODE</code> enabled <code>NTEXT</code> and <code>NVARCHAR</code> as well, which you should use for examples above.</p> <p><em>P.P.S.</em> The same applies to <code>VARCHAR(MAX)</code> and <code>NVARCHAR(MAX)</code> that <em>SQL Server 2005+</em> uses instead of <code>TEXT</code> and <code>NTEXT</code>. You'll need to enable <code>large value types out of row</code> for them with <code>sp_tableoption</code> if you want them to be always stored out of row.</p> <p>As mentioned above and <a href="http://technet.microsoft.com/en-us/library/ms189087.aspx" rel="noreferrer"><strong>here</strong></a>, <code>TEXT</code> is going to be deprecated in future releases:</p> <blockquote> <p>The <code>text in row</code> option will be removed in a future version of <em>SQL Server</em>. Avoid using this option in new development work, and plan to modify applications that currently use <code>text in row</code>. We recommend that you store large data by using the <code>varchar(max)</code>, <code>nvarchar(max)</code>, or <code>varbinary(max)</code> data types. To control in-row and out-of-row behavior of these data types, use the <code>large value types out of row</code> option.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload