如何在SQL Server中查找表关系 [英] how to find table relation ship in sql server
问题描述
hiiiiiiiii,我有一个要求,即我希望查询以以下方式显示
--------表名--------相关表---------
mytable table1
mytable table2
mytable table4
mytable table5
mytable table6
这些是我想显示的方式,它有任何生产方式.数据库中的每个表和关系都可以帮助我……..
在此先感谢ee
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
推荐答案
尝试一下
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
选项1 :右键单击表,然后选择查看依赖项".
选项2:列出依赖于给定表的表
Option 1: Right-click on a table and choose ''View Dependencies''.
Option 2:List tables which are dependent on a given table
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')
在上面的代码中,将WB_EMPLOYEE替换为您的表名.
in the above replace WB_EMPLOYEE with your table name.
请参阅以下链接:
http://www. c-sharpcorner.com/Blogs/5317/how-to-find-table-relationship-in-sql-server-2005-2008.aspx [ http://forums.asp.net/t/1498600.aspx/1 [ ^ ]
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=145340 [ ^ ]
Refer these links:
http://www.c-sharpcorner.com/Blogs/5317/how-to-find-table-relationship-in-sql-server-2005-2008.aspx[^]
http://forums.asp.net/t/1498600.aspx/1[^]
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=145340[^]
这篇关于如何在SQL Server中查找表关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!