2017-02-22 66 views
2

我发现计算器这个问题,几乎回答我的问题:Find all columns of a certain type in all tables in a SQL Server database查找所有表中的类型为nvarchar(最大)的所有列在SQL Server数据库

但我需要找到类型为nvarchar的各个领域(最大值)特别。如果我试试这个:

SELECT table_name [Table Name], column_name [Column Name] 
FROM information_schema.columns where data_type = 'nvarchar(max)' 

它不工作,没有返回。如果我试试这个:

SELECT table_name [Table Name], column_name [Column Name] 
FROM information_schema.columns where data_type = 'nvarchar' 

它的工作原理,但有成百上千的结果,我只关心最大尺寸的字段。如何特别选择所有nvarchar(max)字段?

回答

4

character_maximum_length对于max将为-1。

select 
    table_name as [Table Name] 
    , column_name as [Column Name] 
from information_schema.columns 
where data_type = 'nvarchar' 
    and character_maximum_length=-1 
+0

这工作,谢谢! – Legion

+0

@Legion乐意帮忙! – SqlZim

2
SELECT * FROM INFORMATION_SCHEMA.COLUMNS 
WHERE DATA_TYPE = 'nvarchar' AND CHARACTER_MAXIMUM_LENGTH = -1 
+2

我想你在''nvarchar''和'CHARACTER_MAXIMUM_LENGTH'之间缺少'AND' – Legion

相关问题