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 2008 Forums
 Transact-SQL (2008)
 Foreign key Constrain Column name

Author  Topic 

chiragvm
Yak Posting Veteran

65 Posts

Posted - 2011-12-08 : 09:10:31
Hi to all

I have a two table Tab1 and Tab2
In TAb1 Have 3 Primary Key PK1,Pk2,Pk3
Tab2 has reletionship with Tab1, so All 3 primary column generate in Tab2 like FPk1,FPk2,FPk3
now i want to get associat primary column with foreign key column. how i can get it

my query is dynamic generate so

Select * from Tab2,Tab1
Where
Tab2.Fpk1 = Tab1.Pk1
Tab2.Fpk2 = Tab1.Pk2
Tab2.Fpk3 = Tab1.Pk3


I WANT TO FIND OUT BOLD PART

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-08 : 09:12:51
why is your query dynamic? i cant see any reason for making it dynamic here

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

chiragvm
Yak Posting Veteran

65 Posts

Posted - 2011-12-08 : 09:25:17
in my app user select fields base on selected field i have to generate a query and execute it
i have a list of column in both table but how to identify Tab2.Fpk1 is a foreign key of Tab1.Pk1
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-08 : 09:35:30
you can check sys.foreign_keys catalog view for that

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -