Solved

SQL Query

Posted on 2014-02-06
5
191 Views
Last Modified: 2014-02-26
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
Comment
Question by:Rdichpally
5 Comments
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 250 total points
ID: 39839300
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
 
LVL 9

Assisted Solution

by:rawinnlnx9
rawinnlnx9 earned 250 total points
ID: 39839315
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
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 39839340
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
 
LVL 16

Expert Comment

by:Surendra Nath
ID: 39839493
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
 

Author Closing Comment

by:Rdichpally
ID: 39890840
Thanks.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question