Ever faced a scenario where you know a column name and you want to know which table does it belong to? Here is the query for that if you are using the Microsoft SQL Server.
SELECT S.Name FROM SysObjects S INNER JOIN SysColumns C ON S.ID=C.ID WHERE ObjectProperty(S.ID,'IsUserTable')=1 AND C.Name='ColumnName'
Replace ‘ColumnName’ in the above query with the column name whose table name you are looking for.
The query will return the names of all those tables which contain a column with the given name.






No Comments Yet - be the First!