Solved

how can i see relationship

Posted on 2014-12-06
4
78 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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 …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 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