4

我的数据库中有大量表。我正在搜索名为 的列Country,但不知道哪个表包含该列。是否有特定的查询可以帮助我找到包含该列的表的名称?

4

5 回答 5

7

是的,您可以使用 INFORMATION_SCHEMA.COLUMNS

SELECT DISTINCT 
   TABLE_NAME 
FROM 
   INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'Country'
于 2012-09-04T09:52:31.123 回答
4
SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%ColumnName%'
ORDER BY schema_name, table_name;

替换ColumnName为您的实际列名

于 2012-09-04T09:52:59.040 回答
2
select distinct table_schema, table_name from information_schema.columns where table_name = 'Country';
于 2012-09-04T09:57:00.307 回答
1

您可以在INFORMATION_SCHEMA.COLUMNS

USE YourDBName;
SELECT DISTINCT Table_Name
FROM INFORMATION_SCHEMA.COLUMNS
WHERE Column_Name = 'Country';
于 2012-09-04T09:52:53.083 回答
0

如果我们想在多个表(例如:3 个表)中使用 like 运算符查找列名,请执行以下查询:

select COLUMN_NAME, TABLE_NAME 
from ALL_TAB_COLUMNS 
where TABLE_NAME in ('SIL_RLS_UPLOAD_TMP','SIL_CUSTOMER_MST','SIL_PERSONAL_CUSTOMER_MST')
      and upper(column_name) like upper('%loan%');

如果我们想在所有表中查找带有 like 运算符的列名,请执行以下查询:

select * 
from all_tab_columns 
where upper(column_name) like upper('%card%');
于 2016-04-28T12:01:09.900 回答