是否可以查询包含以下列的表名

LIKE '%myName%'

?


当前回答

在MS SQL Server数据库中,使用此查询获取包含输入文本的表和相应的列名:

SELECT t.name AS tableName, c.name AS columnName 
FROM sys.tables as t 
INNER JOIN sys.columns AS c ON t.object_id=c.object_id 
WHERE c.name LIKE '%<your_search_string>%'

其他回答

SELECT COLUMN_NAME, TABLE_NAME
  FROM INFORMATION_SCHEMA.COLUMNS    
 WHERE COLUMN_NAME LIKE '%myName%'

我出于同样的目的使用了这个,它起到了作用:

  select * from INFORMATION_SCHEMA.COLUMNS
  where TABLE_CATALOG= 'theDatabase'
  and COLUMN_NAME like 'theCol%'

我刚试过,这个效果很好

USE YourDatabseName
GO
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 '%YourColumnName%'
ORDER BY schema_name, table_name;

只将YourDatabaseName更改为数据库,将YourcolumnName更改为您要查找的列名,其余的保持原样。

希望这有所帮助

在MS SQL Server数据库中,使用此查询获取包含输入文本的表和相应的列名:

SELECT t.name AS tableName, c.name AS columnName 
FROM sys.tables as t 
INNER JOIN sys.columns AS c ON t.object_id=c.object_id 
WHERE c.name LIKE '%<your_search_string>%'

像oracle一样,您可以通过以下方式查找表和列:

select table_name, column_name
from user_tab_columns 
where column_name 
like '%myname%';