Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Migration Scripts help

Author  Topic 

GoDaddy
Yak Posting Veteran

64 Posts

Posted - 2009-02-11 : 10:29:50
Let's say you have a Table A.

Table B, C, D have a FK on table A.

Is there a way to find out what are the rows in B, C, D that have a ref on A?

in a scripts

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-11 : 10:50:56
yup. just do

select B.*
from B
JOIN A
ON A.PK=B.FK

select C.*
from C
JOIN A
ON A.PK=C.FK
...
Go to Top of Page

GoDaddy
Yak Posting Veteran

64 Posts

Posted - 2009-02-11 : 11:22:24
thanks,

but is there a more generic solutions? without knowing that B, C, D have a FK.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-11 : 11:24:32
yup..it works whether or not there's fk relationship. what it does is brings all records from first table which has matching value in second table field
Go to Top of Page

GoDaddy
Yak Posting Veteran

64 Posts

Posted - 2009-02-11 : 13:16:26
I was looking for a more generic solution, like inspecting the table schema or something. Without explicitly selecting from specific table
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-11 : 13:49:15
quote:
Originally posted by GoDaddy

I was looking for a more generic solution, like inspecting the table schema or something. Without explicitly selecting from specific table



No you can't.
Go to Top of Page
   

- Advertisement -