sql server 2008中的主外键关系获取方式:
转自:http://www.cnblogs.com/ke10/archive/2012/06/11/2544655.html
SELECT OBJECT_NAME(con.constid) ‘关系名‘ ,
OBJECT_NAME(sf.fkeyid) ‘主键表‘ ,
fcol.name ‘主键‘ ,
OBJECT_NAME(sf.rkeyid) ‘外键表‘ ,
rcol.name ‘外键‘,
st.name‘数据类型‘
FROM sysforeignkeys sf
INNER JOIN sysconstraints con ON sf.constid = con.constid
INNER JOIN sys.syscolumns fcol ON fcol.id = sf.fkeyid
AND fcol.colid = sf.fkey
INNER JOIN sys.syscolumns rcol ON rcol.id = sf.rkeyid
AND rcol.colid = sf.rkey
INNER JOIN sys.systypes st ON fcol.type = st.type
时间: 2024-10-10 22:41:09