Search code examples
sql-serversql-server-2017

SQL Server date datatype becomes nvarchar


After so many years, I have become part of a project that use SQL server. This time it's 2017. I found a very weird behavior when I create a table.

create table test (sampledate date)

If I run above and check the data type of column sampledate, it shows nvarchar instead of 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.


Solution

  • Have a look at this section of the Microsoft documentation. It explains that with down-level clients, the backward compatibility of the date data type is ensured by being converted to String/Varchar. So it may really comes from the DBVisualizer usage.
    For your app, check the version of the client you use.