SQL Server 文本数据类型 Maxlength = 65,535?
我正在使用的软件使用文本字段来存储 XML.从我的在线搜索来看,文本数据类型应该包含 2^31 - 1 个字符.目前,SQL Server 每次都将 XML 截断为 65,535 个字符.我知道这是由 SQL Server 引起的,因为如果我直接在 Management Studio 中向列中添加第 65,536 个字符,它会声明它不会更新,因为字符将被截断.
Software I'm working with uses a text field to store XML. From my searches online, the text datatype is supposed to hold 2^31 - 1 characters. Currently SQL Server is truncating the XML at 65,535 characters every time. I know this is caused by SQL Server, because if I add a 65,536th character to the column directly in Management Studio, it states that it will not update because characters will be truncated.
最大长度真的是 65,535 还是因为数据库是在早期版本的 SQL Server (2000) 中设计的,并且它使用旧的 text
数据类型而不是 2005 的数据类型?
Is the max length really 65,535 or could this be because the database was designed in an earlier version of SQL Server (2000) and it's using the legacy text
datatype instead of 2005's?
如果是这种情况,在 SQL Server 2005 中将数据类型更改为 Text
会解决这个问题吗?
If this is the case, will altering the datatype to Text
in SQL Server 2005 fix this issue?
推荐答案
这是 SSMS 的限制,而不是文本字段,但您应该使用 varchar(max),因为文本已被弃用
that is a limitation of SSMS not of the text field, but you should use varchar(max) since text is deprecated
这里也是一个快速测试
create table TestLen (bla text)
insert TestLen values (replicate(convert(varchar(max),'a'), 100000))
select datalength(bla)
from TestLen
为我返回 100000
Returns 100000 for me
相关文章