简体   繁体   English

将ntext转换为varbinary(max)

[英]Convert ntext to varbinary(max)

Is it possible to convert column values from ntext to varbinary(max) in SQL server 2000 R2 ? 是否可以在SQL server 2000 R2中将列值从ntext转换为varbinary(max)

Doing a workaround I found, initially I need to convert from ntext to nvarchar() then from nvarchar() to varbinary(max) . 做一个解决方法,我发现最初需要将ntext转换为nvarchar()然后再将nvarchar()varbinary(max)

No this is not a supported direct conversion. 不,这不是受支持的直接转换。

As shown in the Data Type Conversion topic ( image ) you can only cast from ntext to one of the other string datatypes or to XML. 如“ 数据类型转换”主题( image )中所示,您只能从ntext转换为其他字符串数据类型之一或XML。

But you don't need to do this anyway. 但是您仍然不需要这样做。

The argument 争论

Because i want the data to be stored in binary format. 因为我希望数据以二进制格式存储。

doesn't make sense as it won't affect the physical storage anyway. 没有任何意义,因为它仍然不会影响物理存储。 See below that the actual bytes stored are the same. 参见下文,实际存储的字节相同。

CREATE TABLE T
(
A NVARCHAR(MAX),
B VARBINARY(MAX)
)

INSERT INTO T 
SELECT N'foobar',
       CAST(N'foobar' AS VARBINARY(MAX))

在此处输入图片说明

It just affects how the bytes are interpreted logically. 它仅影响字节在逻辑上的解释方式。 Storing as varbinary datatype would make the data more difficult to work with (need to cast back to nvarchar to use as a string) and your application more fragile. 存储为varbinary数据类型将使数据更难以使用(需要将其转换回nvarchar用作字符串),并且应用程序也更脆弱。 Conversions between any data type and the binary data types are not guaranteed to be the same between versions of SQL Server. 在任何版本的SQL Server之间,任何数据类型和二进制数据类型之间的转换都不能保证相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM