Saturday, August 25, 2007

How to find tables related to a column?

You are a DBA for a database, sometimes you need to know tables related to a column.
You can use this query to find that:

If you use Oracle database:

SELECT *
FROM all_tab_cols
WHERE table_name like ‘PartOfTable%’
AND column_name = ‘ColumnName’

If you use SQL Server 2005 database:
SELECT t1.*
FROM sys.columns t1 INNER JOIN
sys.objects t2 ON t1.object_id = t2.object_id
WHERE t1.name = 'ColumnName'

No comments:

Post a Comment