[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

how can i see relationship

Posted on 2014-12-06
4
Medium Priority
?
87 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
[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
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 11

Accepted Solution

by:
HuaMinChen earned 2000 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 8

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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 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