如何在SQL Server中获取特定列名的匹配表?

时间:2011-10-21 14:49:45

标签: sql-server sql-server-2005 sql-server-2008

我想找到所有匹配的表格列表,其中columnname ='Letter'?

由于

4 个答案:

答案 0 :(得分:6)

SELECT TABLE_SCHEMA,
       TABLE_NAME
FROM   INFORMATION_SCHEMA.COLUMNS
WHERE  COLUMN_NAME = 'Letter'  

答案 1 :(得分:1)

select TABLE_NAME
from INFORMATION_SCHEMA.COLUMNS
where COLUMN_NAME = 'Letter'

答案 2 :(得分:1)

  select 
  type_desc,
  sch.name as 'schema name',
  obj.name as 'table', 
  col.name as columnname,
  ty.name as  columntype,
  col.max_length as columnmaxlength,
  is_identity
  from  sys.objects obj 
  inner join sys.all_columns col
  on obj.object_id = col.object_id
  inner join sys.schemas sch
  on obj.schema_id = sch.schema_id
  inner join sys.types ty
  on col.system_type_id = ty.system_type_id 
 where type ='U'
 and col.name like '%letter%'
 order by type_desc,sch.name, obj.name, col.name

答案 3 :(得分:0)

上面的代码将为您提供TABLES以及VIEWS 排除VIEWS

SELECT C.TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS C,INFORMATION_SCHEMA.TABLES T
WHERE C.TABLE_NAME=T.TABLE_NAME AND C.COLUMN_NAME = 'YOUR_COLUMN_NAME'
AND T.TABLE_TYPE='BASE TABLE'