Solved

SQL Query

Posted on 2014-02-06
5
178 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:
ScottPletcher 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Meetings to discuss business process can waste time, and often do .  The meeting's dialog can get confusing when participants have different professional perspectives and backgrounds.  A jointly-developed process picture helps wade through the confu…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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…

760 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

24 Experts available now in Live!

Get 1:1 Help Now