我知道一个字段的名称,但我不知道该表。
use "DatabaseName"
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'%Company%'
ORDER BY schema_name,table_name;
在Microsft SqL中,我用上面的语法得到了结果,但是我没有在WinSQL中得到结果。
答案 0 :(得分:0)
这实际上取决于您要连接的数据库类型,但我怀疑它与SQL Server的INFORMATION_SCHEMA.COLUMNS相同。在SQL Server中,您只需编写:
DECLARE @col varchar(50);
SET @col = 'my_col';
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE COLUMN_NAME = @col;