find列名称的所有表名称?

如何获得给定列名称存在的所有表名称? 我想要在SQL Server中的“喜欢”的名称。 例如 :-

select TableNames where columnname like '%MyColumn%' 

请帮帮我

请尝试下面的查询。 使用sys.columns获取详细信息: –

 SELECT c.name AS ColName, t.name AS TableName FROM sys.columns c JOIN sys.tables t ON c.object_id = t.object_id WHERE c.name LIKE '%MyCol%'; 

你可以这样做:

 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 '%MyColumn%' ORDER BY schema_name, table_name; 

参考:

  • SQL SERVER – 查询从数据库的所有表中查找列

像这样试试:对于SQL SERVER 2008+

 SELECT c.name AS ColName, t.name AS TableName FROM sys.columns c JOIN sys.tables t ON c.object_id = t.object_id WHERE c.name LIKE '%MyColumnaName%' 

要么

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

或者像这样的东西:

 SELECT name FROM sys.tables WHERE OBJECT_ID IN ( SELECT id FROM syscolumns WHERE name like '%COlName%' )