如何找到哪些外键引用了表上的索引

编程入门 行业动态 更新时间:2024-10-26 14:38:54
本文介绍了如何找到哪些外键引用了表上的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个想要删除的非聚集索引(它是聚集索引的副本).但是,它正被外键约束使用.我希望能够确定哪个约束正在使用索引,以便我可以更新它以使用主键索引.

I have a non clustered index I would like to drop (it is a duplicate of the clustered index). However, it is being used by a foreign key constraint. I would like to be able to identify which constraint is using the index, so I can update it to use the primary key index.

当我试图放下它时:

DROP INDEX [idx_duplicate] ON [dbo].[MyTable]

我收到一个错误:

索引dbo.MyTable.idx_duplicate"上不允许使用显式的 DROP INDEX.它用于强制执行 FOREIGN KEY 约束.

An explicit DROP INDEX is not allowed on index 'dbo.MyTable.idx_duplicate'. It is being used for FOREIGN KEY constraint enforcement.

我试图通过以下查询找到罪魁祸首,但没有成功:

I tried to find the culprit with the following query but no luck:

SELECT name FROM sys.foreign_keys WHERE OBJECT_NAME (referenced_object_id) = 'idx_duplicate'

推荐答案

类似的东西

Select f.name, object_name(f.parent_object_id) From sys.foreign_keys f inner join sys.indexes i on f.referenced_object_id = i.object_id and f.key_index_id = i.index_id Where i.name = 'idx_duplicate' and i.object_id = object_id('[dbo].[MyTable]')

更多推荐

如何找到哪些外键引用了表上的索引

本文发布于:2023-10-23 00:20:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519183.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表上   索引

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!