Solved

SQL Query

Posted on 2014-02-06
5
184 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now