SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Get relationship via SQL
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

vishal_7
Posting Yak Master

127 Posts

Posted - 08/30/2005 :  14:46:16  Show Profile  Reply with Quote
Hey,

is it possible to get the relationship of a table via sql? Like I need to know which relations the table t has. Is that possible?

Thanks

TG
Flowing Fount of Yak Knowledge

USA
6062 Posts

Posted - 08/30/2005 :  16:36:20  Show Profile  Reply with Quote
One way is from a query analyzer window: sp_help <tableName>
Gives you a lot of info about the table including foreign Keys and tables referenced by foreign keys. (relationships are defined by foreign keys)



Be One with the Optimizer
TG
Go to Top of Page

robvolk
Most Valuable Yak

USA
15676 Posts

Posted - 08/30/2005 :  18:54:01  Show Profile  Visit robvolk's Homepage  Reply with Quote
You can also try selecting from INFORMATION_SCHEMA.TABLE_CONSTRAINTS and INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS, these give you the same info as sp_help but in a different format.
Go to Top of Page

vishal_7
Posting Yak Master

127 Posts

Posted - 08/31/2005 :  09:56:22  Show Profile  Reply with Quote
thanks guys, I will try it out and report when there are any probs.
Go to Top of Page

vishal_7
Posting Yak Master

127 Posts

Posted - 08/31/2005 :  10:42:37  Show Profile  Reply with Quote
Isnt sp_fkeys much better for that purpose?
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22761 Posts

Posted - 08/31/2005 :  10:46:23  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Yes you can use sp_pkeys or sp_fkeys also


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000