Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting all tables and columns that have a foreign key references to the given table's key

 
sandeeprajsingh tandon
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I wrote a query for getting all tables and columns that have a foreign key references to the given table's key. Can you help me write it efficiently. Basically i want to avoid the outermost select statement which is written only to get the "referenced column name"..is there a way to get the referenced column name in the 2nd select statement thereby avoiding the outermost.

 
Dave Tolls
Ranch Hand
Posts: 2102
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first thought is, how do you know it'll make it more efficient? You might need to define "efficient" to answer that one.

My second is, unless you want the column_name to be part of the distinct, then you can't.
If it can be part of the distinct then you can simply put those joins and filters into the inner query.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic