--表的外键约束
SELECT 外键表ID=b.fkeyid
,外键表名称=object_name(b.fkeyid)
,外键列ID=b.fkey
,外键列名=(SELECT name FROM syscolumns WHERE colid=b.fkey AND id=b.fkeyid)
,主键表ID=b.rkeyid
,主键表名=object_name(b.rkeyid)
,主键列ID=b.rkey
,主键列名=(SELECT name FROM syscolumns WHERE colid=b.rkey AND id=b.rkeyid)
,级联更新=ObjectProperty(a.id,'CnstIsUpdateCascade')
,级联删除=ObjectProperty(a.id,'CnstIsDeleteCascade')
FROM sysobjects a
join sysforeignkeys b on a.id=b.constid
join sysobjects c on a.parent_obj=c.id
where a.xtype='f' AND c.xtype='U'
--查询一个表的所有外键:
SELECT 主键列ID=b.rkey
,主键列名=(SELECT name FROM syscolumns WHERE colid=b.rkey AND id=b.rkeyid)
,外键表ID=b.fkeyid
,外键表名称=object_name(b.fkeyid)
,外键列ID=b.fkey
,外键列名=(SELECT name FROM syscolumns WHERE colid=b.fkey AND id=b.fkeyid)
,级联更新=ObjectProperty(a.id,'CnstIsUpdateCascade')
,级联删除=ObjectProperty(a.id,'CnstIsDeleteCascade')
FROM sysobjects a
join sysforeignkeys b on a.id=b.constid
join sysobjects c on a.parent_obj=c.id
where a.xtype='f' AND c.xtype='U'
and object_name(b.rkeyid)='titles'
249.标的外键约束
最新推荐文章于 2021-02-01 23:39:11 发布