是否可以查询包含以下列的表名
LIKE '%myName%'
?
是否可以查询包含以下列的表名
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>%'
其他回答
它将返回table_name、schema_name、column_name
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 '%colName%'
ORDER BY schema_name,
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;
像oracle一样,您可以通过以下方式查找表和列:
select table_name, column_name
from user_tab_columns
where column_name
like '%myname%';
我们还可以使用以下语法:-
select * from INFORMATION_SCHEMA.COLUMNS
where COLUMN_NAME like '%clientid%'
order by TABLE_NAME
我出于同样的目的使用了这个,它起到了作用:
select * from INFORMATION_SCHEMA.COLUMNS
where TABLE_CATALOG= 'theDatabase'
and COLUMN_NAME like 'theCol%'