查找被另一个约束引用的所有约束
Find all constraints that are referenced by another constraint
Meldung 3725, Ebene 16, Status 0, Zeile 327
The constraint 'UQ_users_email' is being referenced by table 'posts', foreign key constraint 'FK_posts_users'.
Meldung 3727, Ebene 16, Status 0, Zeile 327
Could not drop constraint. See previous errors.
除了解析错误信息,我如何才能得到所有阻止删除某个约束的约束的列表?
FK 取决于(方块掉落的)PK/UQ of referenced table,任何类型的约束都会阻止它所依赖的列的删除。可以通过此查询列出 tables 引用目标 table 的列表:
select
object_schema_name(fk.fkeyid) + '.' + object_name(fk.fkeyid) as [REF_BY],
object_name(fk.constid) as [REF_NAME]
from sys.sysforeignkeys fk
inner join sys.sysconstraints cs on cs.constid = fk.constid
where fk.rkeyid = object_id('dbo.my_target_table_with_constraint_to_drop', 'u')
order by 1, 2
所有这些 FK 将阻止 PK/UQ 从目标 table
中掉落
Meldung 3725, Ebene 16, Status 0, Zeile 327
The constraint 'UQ_users_email' is being referenced by table 'posts', foreign key constraint 'FK_posts_users'.
Meldung 3727, Ebene 16, Status 0, Zeile 327
Could not drop constraint. See previous errors.
除了解析错误信息,我如何才能得到所有阻止删除某个约束的约束的列表?
FK 取决于(方块掉落的)PK/UQ of referenced table,任何类型的约束都会阻止它所依赖的列的删除。可以通过此查询列出 tables 引用目标 table 的列表:
select
object_schema_name(fk.fkeyid) + '.' + object_name(fk.fkeyid) as [REF_BY],
object_name(fk.constid) as [REF_NAME]
from sys.sysforeignkeys fk
inner join sys.sysconstraints cs on cs.constid = fk.constid
where fk.rkeyid = object_id('dbo.my_target_table_with_constraint_to_drop', 'u')
order by 1, 2
所有这些 FK 将阻止 PK/UQ 从目标 table
中掉落