在SQLServer中主外键是什么,以及主外键如何创建,在这里就不说了,不懂的可以点击这里,这篇文章也是博客园的博友写的,我觉得总结的很好;
此篇文章主要介绍通过SQL脚本来查看Sqlserver中主外键关系:
SELECT f.name AS '关系名称',
OBJECT_NAME(f.parent_object_id) AS '表名称',
COL_NAME(fc.parent_object_id,fc.parent_column_id) AS '字段名称',
OBJECT_NAME (f.referenced_object_id) AS '关联表名称',
COL_NAME(fc.referenced_object_id,fc.referenced_column_id) AS '关联字段名称'
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id