我在 stackoverflow 上发现了这个问题,它几乎回答了我的问题:Find all columns of a certain type in all tables in a SQL Server database
但是我需要专门查找 nvarchar(max) 类型的所有字段。如果我尝试这个:
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) 字段?
最佳答案
对于 max
,character_maximum_length
将为 -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
关于sql - 查找 SQL Server 数据库中所有表中 nvarchar(max) 类型的所有列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42403058/