Solved

how can i see relationship

Posted on 2014-12-06
4
75 Views
Last Modified: 2014-12-30
Hi,
I have tables in sql server 2008 and that tables have 1-1 or 1-n relationship

lets say i have table x and table x has reationship to 5 other tables

how can i see that in some kind of  visio in sqlserver .

Thanks
0
Comment
Question by:sam2929
4 Comments
 
LVL 7

Expert Comment

by:Camillia
ID: 40485154
See screenshot

1.Sql Server Management Studio ->Object Explorer->Databases->Database Node
2. find a node named Database Diagrams
3.Right Click on "Database Diagrams" node and select new database diagram. You'll get a wizard.

diagram
0
 
LVL 10

Accepted Solution

by:
HuaMinChen earned 500 total points
ID: 40485396
Hi,
You can list out all FK and PK of the tables by
SELECT OBJECT_NAME(OBJECT_ID) AS NameofConstraint,
SCHEMA_NAME(schema_id) AS SchemaName,
OBJECT_NAME(parent_object_id) AS TableName,
type_desc AS ConstraintType
FROM sys.objects 
WHERE type_desc IN ('FOREIGN_KEY_CONSTRAINT','PRIMARY_KEY_CONSTRAINT')
GO

Open in new window


as all relationships should involve PK and FK of the relevant tables.
0
 
LVL 7

Expert Comment

by:Dung Dinh
ID: 40486235
Hi,

The simplest way, you right click on the table then choose View Dependencies -> Objects on which ... depends
ObjectDependencies.PNG
Another way, use script to find out FOREIGN KEY
SELECT t.[Table Name],
t.[Foreign Key Name],
t.[Parent Table],
t.[Referenced Column]
FROM (
SELECT
 '[' + SCHEMA_NAME(fk.[schema_id]) + '].[' + OBJECT_NAME(fk.parent_object_id) + ']' AS [Table Name]
,fk.name [Foreign Key Name]
,OBJECT_NAME(fk.referenced_object_id) [Parent Table]
,COL_NAME(fkc.referenced_object_id,fkc.referenced_column_id) AS [Referenced Column]
FROM sys.foreign_keys fk
   INNER JOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id) t
--WHERE   t.[Table Name] =  N'[dbo].[FactFinance]'
ORDER BY [Table Name] ASC

Open in new window

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

19 Experts available now in Live!

Get 1:1 Help Now