在用户表中按名称查找列
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在用户表中按名称查找列相关的知识,希望对你有一定的参考价值。
Perform a search of all user tables in the current database to locate a column defined in a user table that matches a certain name. The first query looks for an exact column name and the second one returns all column names which match a keyword (using the LIKE operator).
-- find a column with a specific name SELECT schema_name(o.schema_id) + '.' + o.[name] AS tablename, c.[name] AS columnname, t.[name] AS datatype, c.max_length, c.[PRECISION], c.scale, c.is_nullable, c.is_identity FROM sys.columns c INNER JOIN sys.objects o ON o.[object_id] = c.[object_id] AND o.[TYPE] = 'U' LEFT JOIN sys.types t ON t.system_type_id = c.system_type_id AND t.user_type_id = c.user_type_id WHERE c.[name] = 'COLUMNTOFIND' -- find a column that matches a keyword SELECT schema_name(o.schema_id) + '.' + o.[name] AS tablename, c.[name] AS columnname, t.[name] AS datatype, c.max_length, c.[PRECISION], c.scale, c.is_nullable, c.is_identity FROM sys.columns c INNER JOIN sys.objects o ON o.[object_id] = c.[object_id] AND o.[TYPE] = 'U' LEFT JOIN sys.types t ON t.system_type_id = c.system_type_id AND t.user_type_id = c.user_type_id WHERE c.[name] LIKE '%COLUMNTOFIND%' ORDER BY schema_name(o.schema_id), o.[name]
以上是关于在用户表中按名称查找列的主要内容,如果未能解决你的问题,请参考以下文章