是否可以查询包含以下列的表名
LIKE '%myName%'
?
是否可以查询包含以下列的表名
LIKE '%myName%'
?
当前回答
我刚试过,这个效果很好
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更改为您要查找的列名,其余的保持原样。
希望这有所帮助
其他回答
我出于同样的目的使用了这个,它起到了作用:
select * from INFORMATION_SCHEMA.COLUMNS
where TABLE_CATALOG= 'theDatabase'
and COLUMN_NAME like 'theCol%'
SELECT [TABLE_NAME] ,
[INFORMATION_SCHEMA].COLUMNS.COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE INFORMATION_SCHEMA.COLUMNS.COLUMN_NAME LIKE '%NAME%' ;
SELECT table_schema + '.' + table_name,
column_name
FROM [yourdatabase].information_schema.columns
WHERE column_name LIKE '%myName%'
这将为您提供需要查找的列的表名。
要获取完整信息:列名、表名以及表的架构。。
SELECT COLUMN_NAME, TABLE_NAME, TABLE_SCHEMA
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%col_Name%'
您可以在SQL Server中使用以下查询。
SELECT column_name AS 'ColumnName',
table_name AS 'TableName'
FROM information_schema.columns
WHERE column_name LIKE '%columnname%'
AND table_schema = 'schema'
ORDER BY tablename,
columnname;