Solved

SQL Query

Posted on 2014-02-06
5
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Gain an elementary understanding of Blockchain technology.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

696 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