列出某张表相关的 FK Name
select distinct name from sys.objects where object_id in
(   select fk.constraint_object_id from sys.foreign_key_columns as fk
    where fk.referenced_object_id =
        (select object_id from sys.tables where name = 'TableName')
)

列出主外键关系

select t.name as TableWithForeignKey, fk.constraint_column_id as FK_PartNo , c.name as ForeignKeyColumn
from sys.foreign_key_columns as fk
inner join sys.tables as t on fk.parent_object_id = t.object_id
inner join sys.columns as c on fk.parent_object_id = c.object_id and fk.parent_column_id = c.column_id
where fk.referenced_object_id = (select object_id from sys.tables where name = 'User')
order by TableWithForeignKey, FK_PartNo;

删除外键

alter table Membership drop FK_Membership_Organization

相关文章:

  • 2022-02-16
  • 2022-12-23
  • 2021-11-25
  • 2021-10-28
  • 2021-12-30
  • 2022-12-23
  • 2021-12-30
  • 2021-09-16
猜你喜欢
  • 2022-02-18
  • 2022-12-23
  • 2021-12-24
  • 2022-01-16
  • 2022-12-23
  • 2021-12-21
  • 2021-04-11
相关资源
相似解决方案