gpt4 book ai didi

sql-server - SQL Server : implicit data type conversions chart

转载 作者:行者123 更新时间:2023-12-03 00:13:39 25 4
gpt4 key购买 nike

据我所知,根据this chart ,从 VARBINARY 到 DATE 的隐式转换应该没问题。但是,当我尝试以下代码时,SQL Server 响应“不允许从数据类型 varbinary(max) 到 date 的隐式转换。请使用 CONVERT 函数运行此查询。”

CREATE TABLE [dbo].[CONVERSION_TEST](
[mydate] [date] NULL
) ON [PRIMARY]

GO


declare @bin varbinary(MAX) = NULL
insert into conversion_test values (@bin)

我在 SQL Server 2012(版本 11.0.3128)上运行此程序。

最佳答案

刚刚找到这个连接帖子:

Microsoft Connect

其中有来自 Microsoft 的以下声明:

Posted by Microsoft on 05/03/2008 at 13:23 After some serious discussion, we believe that the current design is good especially given it's not an interesting scenario and we already support explicit conversion for the new date/time types.

On the other hand, we also think that it's not necessarily a good thing given we supported too many implicit conversions on existing types. Conversion to/from binary is a dangerous thing, and requiring explicit conversion makes sense. It's unfortunate that ALTER TABLE behavior is tied to implicit conversion, but you can always work around it by creating a new column, issue an update, and then drop old column if that's main scenario you worried.

So if no strong objection, we're going to do the followings: - Fixing the BOL to indicate that there's no implicit conversion support from binary/varbinary to new date/time types - Close this as 'By Design'

thanks

因此,他们似乎决定禁止这种隐式转换,但不更新该图表。

关于sql-server - SQL Server : implicit data type conversions chart,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18269115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com