• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

SQL Query

I need to find out the types of relationship between my tables in the database (1to1 or 1toMany etc).

Are there any good queries to find out the relationships between my tables in the database? Thanks.

Rajender Dichpally
0
Rdichpally
Asked:
Rdichpally
2 Solutions
 
Scott PletcherSenior DBACommented:
If there are explicit foreign keys for the relationship, you can query the sys.foreign_key* system views.  Other than that, there is nothing inherent in SQL to describe the relationships between tables.
0
 
rawinnlnx9Commented:
In SQL Management Studio. Right-click your table and modify. If there are relationships you'll see them there listed. You can also add them.

You can also right-click your db and build a diagram by selecting the tables you want to include.
0
 
Lee SavidgeCommented:
If there are no fixed relationships in the database, then you are going to need to try and work it out from the columns in the table to see if they refer to other tables. I've worked with systems in the past where the relationships are not managed by the database (no idea why), rather they are managed via code in the application that owns the database. As the application support contract didn't allow direct access to the database, it didn't matter particularly.
0
 
Surendra NathTechnology LeadCommented:
adding to what @rawin said

you can use database diagrams to check the relationships between the tables visually and easily in one shot....

You can use the below video link to generate a database diagram in your database.
http://www.youtube.com/watch?v=wMbPRHeYvMU
0
 
RdichpallyAuthor Commented:
Thanks.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now