If you need search and find which table a certain field presides, but the tables were originally named very poorly.
If you have this query below that has helped searching for a column name within a table. The results show you the Table Name, Schema Name and Column Name. But you need to search for a value, and you need to know which table the value is in. For example, it would like the results to show "Table Name", "Schema Name" and "Column Name" when you search for "Value1".
USE DATABASE NAME
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 '%results%'
ORDER BY schema_name, table_name;
If you have this query below that has helped searching for a column name within a table. The results show you the Table Name, Schema Name and Column Name. But you need to search for a value, and you need to know which table the value is in. For example, it would like the results to show "Table Name", "Schema Name" and "Column Name" when you search for "Value1".
USE DATABASE NAME
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 '%results%'
ORDER BY schema_name, table_name;
Comments
Post a Comment
Please avoid link comments