当需要的长度<8000时,TEXT比varchar有什么优势?

发布于 2024-11-29 17:45:43 字数 420 浏览 5 评论 0 原文

SQL Server Text 类型与 varchar 数据类型

根据经验,如果您需要文本值超过 200 字符并且不要在此列上使用联接,请使用 TEXT。

否则使用 VARCHAR。

假设我的数据现在有 4000 个字符,并且我不在此列上使用联接。由此可见,与使用 varchar(4000) 相比,使用 TEXT/varchar(max) 更有利。

为什么会这样呢? (在这种情况下,TEXT/varchar(max) 相对于普通 varchar 有什么优势?)

SQL Server Text type vs. varchar data type:

As a rule of thumb, if you ever need you text value to exceed 200
characters AND do not use join on this column, use TEXT.

Otherwise use VARCHAR.

Assuming my data now is 4000 characters AND i do not use join on this column. By that quote, it is more advantageous to use TEXT/varchar(max) compared to using varchar(4000).

Why so? (what advantage does TEXT/varchar(max) have over normal varchar in this case?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一人独醉 2024-12-06 17:45:43

TEXT 已弃用,请改用 nvarchar(max)varchar(max)varbinary(max)http://msdn.microsoft.com/en-us/library/ms187993.aspx

TEXT is deprecated, use nvarchar(max), varchar(max), and varbinary(max) instead: http://msdn.microsoft.com/en-us/library/ms187993.aspx

盛夏已如深秋| 2024-12-06 17:45:43

我不同意 200 的事情,因为它没有得到解释,除非它与已弃用的 相关“行中文本”选项

  • 如果您的数据有 4000 个字符,则使用 char(4000)。它是固定长度
  • 文本已弃用
  • BLOB 类型速度较慢

I disagree with the 200 thing because it isn't explained, unless it relate to the deprecated "text in row" option

  • If your data is 4000 characters then use char(4000). It is fixed length
  • Text is deprecated
  • BLOB types are slower
原谅过去的我 2024-12-06 17:45:43

在旧版本的 SQL(2000 及更早版本?)中,最大行长度为 8 KB(或 8060 字节)。如果您对大量长文本列使用 varchar,它们将包含在此长度中,而任何文本列则不会,因此您可以在一行中保留更多文本。

此问题已在最新版本的 SQL 中得到解决。

此 MSDN 页面包含以下语句:

SQL Server 2005 支持行溢出存储,从而启用变量
要被推离行的长度列。仅存储一个 24 字节的根
被推出行的可变长度列的主记录;因为
其中,有效行限制高于以前的版本
SQL Server 的。有关详细信息,请参阅“行溢出数据
SQL Server 2005 联机丛书中的“超过 8 KB”主题。

In old versions of SQL (2000 and earlier?) there was a max row length of 8 KB (or 8060 bytes). If you used varchar for lots of long text columns they would be included in this length, whereas any text columns would not, so you can keep more text in a row.

This issue has been worked around in more recent versions of SQL.

This MSDN page includes the statement:

SQL Server 2005 supports row-overflow storage which enables variable
length columns to be pushed off-row. Only a 24-byte root is stored in
the main record for variable length columns pushed out of row; because
of this, the effective row limit is higher than in previous releases
of SQL Server. For more information, see the "Row-Overflow Data
Exceeding 8 KB" topic in SQL Server 2005 Books Online.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文