简体   繁体   English

SQL Server日期数据类型变为nvarchar

[英]SQL Server date datatype becomes nvarchar

After so many years, I have become part of a project that use SQL server. 经过这么多年,我已经成为使用SQL Server的项目的一部分。 This time it's 2017. I found a very weird behavior when I create a table. 这次是2017年。创建表时,我发现了一个非常奇怪的行为。

create table test (sampledate date)

If I run above and check the data type of column sampledate , it shows nvarchar instead of date. 如果在上面运行并检查sampledate列的数据类型,它将显示nvarchar而不是date。 This causes an error in my application. 这在我的应用程序中导致错误。

Btw I'm using DBVisualizer to check the data type, I believe this is not because of this tool. 顺便说一句,我正在使用DBVisualizer检查数据类型,我相信这不是因为这个工具。

Have a look at this section of the Microsoft documentation . 请查看Microsoft文档的这一部分。 It explains that with down-level clients, the backward compatibility of the date data type is ensured by being converted to String/Varchar. 它解释说,对于下层客户端,可以通过将date数据类型转换为String / Varchar来确保其向后兼容性。 So it may really comes from the DBVisualizer usage. 因此,它可能确实来自DBVisualizer的用法。
For your app, check the version of the client you use. 对于您的应用,请检查您使用的客户端的版本。

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

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