Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
hiiiiiiiii, i have a requirement such that,i want query which displays following way
-------- tablename--------related tables---------
mytable table1
mytable table2
mytable table4
mytable table5
mytable table6
these is the way i want to disply is there any way to produce.each table in the database and relation ships plssss help me..........
thanks in advanceeeee
Posted
Updated 6-Nov-11 19:43pm
v2
Comments
Sergey Alexandrovich Kryukov 7-Nov-11 1:51am    
Must be some rare kind of ship that even I don't know. All I know she might have a relation with a ram; I have no idea what table to you mean. :-)
--SA
[no name] 7-Nov-11 5:21am    
Do you what to get dependence of a Table?

Try this
SQL
Select
	object_name(rkeyid) Parent_Table,
	object_name(fkeyid) Child_Table,
	object_name(constid) FKey_Name,
	c1.name FKey_Col,
	c2.name Ref_KeyCol
From
	sys.sysforeignkeys s
	Inner join sys.syscolumns c1
		on ( s.fkeyid = c1.id And s.fkey = c1.colid )
	Inner join syscolumns c2
		on ( s.rkeyid = c2.id And s.rkey = c2.colid )
Order by Parent_Table,Child_Table
 
Share this answer
 
Option 1: Right-click on a table and choose 'View Dependencies'.

Option 2:List tables which are dependent on a given table

SQL
Select
S.[name] as 'Dependent_Tables'
From
sys.objects S inner join sys.sysreferences R
on S.object_id = R.rkeyid
Where
S.[type] = 'U' AND
R.fkeyid = OBJECT_ID('WB_EMPLOYEE')



in the above replace WB_EMPLOYEE with your table name.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900