While investigating a question on Stackoverflow, I discovered that sp_columns
, which uses sys.spt_columns_odbc_view
, is returning the wrong / unexpected DATA_TYPE
& TYPE_NAME
for NVARCHAR(MAX)
. It's returning NTEXT
for NVARCHAR
columns and I can't figure out why. Does anyone have any insight?
CREATE TABLE [dbo].[deleteTable](
[v] [nvarchar](max) NULL,
[t] [ntext] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
select
c.name
,c.system_type_id
,ty.name
,ty.precision
,t.name
from
sys.columns c
inner join
sys.tables t on t.object_id = c.object_id
inner join
sys.types ty on ty.system_type_id = c.system_type_id
where
t.name = 'deleteTable'
exec sp_columns @table_name = 'deleteTable'
Best Answer
I figured out why you get
NTEXT
but do not know why this is done. This note may be relevant:In the definition of
sys.spt_columns_odbc_view
there is a piece of code:In your case
ELSE d.type_name COLLATE database_default
this is being executed because the data type is -10.sys.spt_datatype_info
uses sp_datatype_info.If you execute below code you will see where
NTEXT
is coming from.