SQL查询数据库中所有指定类型的字段名称和所在的表名

--查询数据库中所有指定类型的字段名称和所在的表名
--eg: 下面查的是当前数据库中 所有字段类型为 nvarchar(max) 的字段名和表名
SELECT  cols.object_id ,
        cols.column_id ,
        cols.name AS ColumnName ,
        TYPE_NAME(cols.system_type_id) AS ColumnType ,
        cols.max_length ,
        obj.name AS TableName
FROM    sys.columns cols
        LEFT JOIN sys.objects AS obj ON cols.object_id = obj.object_id
WHERE   TYPE_NAME(system_type_id) = 'nvarchar'
        AND max_length = -1

猜你喜欢

转载自blog.csdn.net/yousss/article/details/80266932