是否可以查询包含以下列的表名
LIKE '%myName%'
?
是否可以查询包含以下列的表名
LIKE '%myName%'
?
当前回答
我出于同样的目的使用了这个,它起到了作用:
select * from INFORMATION_SCHEMA.COLUMNS
where TABLE_CATALOG= 'theDatabase'
and COLUMN_NAME like 'theCol%'
其他回答
SELECT COLUMN_NAME, TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%myName%'
我们还可以使用以下语法:-
select * from INFORMATION_SCHEMA.COLUMNS
where COLUMN_NAME like '%clientid%'
order by TABLE_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;
您可以尝试以下查询:
USE AdventureWorks
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 '%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更改为您要查找的列名,其余的保持原样。
希望这有所帮助