在用户表中按名称查找列

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).
  1. -- find a column with a specific name
  2. 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
  3. FROM sys.columns c
  4. INNER JOIN sys.objects o ON o.[object_id] = c.[object_id]
  5. AND o.[TYPE] = 'U'
  6. LEFT JOIN sys.types t ON t.system_type_id = c.system_type_id
  7. AND t.user_type_id = c.user_type_id
  8. WHERE c.[name] = 'COLUMNTOFIND'
  9.  
  10. -- find a column that matches a keyword
  11. 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
  12. FROM sys.columns c
  13. INNER JOIN sys.objects o ON o.[object_id] = c.[object_id]
  14. AND o.[TYPE] = 'U'
  15. LEFT JOIN sys.types t ON t.system_type_id = c.system_type_id
  16. AND t.user_type_id = c.user_type_id
  17. WHERE c.[name] LIKE '%COLUMNTOFIND%'
  18. ORDER BY schema_name(o.schema_id), o.[name]

以上是关于在用户表中按名称查找列的主要内容,如果未能解决你的问题,请参考以下文章

在flex中按名称查找后代子项

在 Visual Studio Code 中按名称查找文件

如何在pyqt中按名称查找对象?

在 XmlNode 数组中按名称查找值

csharp 在WPF VisualTree中按名称查找控件

在R中按名称删除列[重复]