Wednesday, November 30, 2011

SQL Tip: Find Table(s) Having A Particular Column

This SQL query is my savior for a long time now. Thought I would just share it with all budding SQL developers.

Q: How to find the table(s) which contain a particular column which I know?
A: Below is the query that would do the trick.

SELECT name 
FROM sys.objects 
WHERE object_id IN 
(
SELECT object_id 
FROM sys.columns 
WHERE name = [columnname] --Column which you would want to locate
)

This query will return all tables which contains the specific column. And this query also would save your time immensely.

VAIDY

2 comments:

Anonymous said...

select table_name from information_schema.columns where column_name = [columnname]

David Musgrave said...

Don't forget the Tables Containing Field Lookup from the Resource Information window in the Support Debugging Tool.

http://aka.ms/SDT

David
http://blogs.msdn.com/DevelopingForDynamicsGP/

Post a Comment

Blog has moved, searching new blog...