唯一/主键的执行-删除索引

问题描述:

我正在尝试删除索引:

DROP INDEX PK_CHARGES

但我收到此错误

不能删除用于执行唯一/主键的索引

cannot drop index used for enforcement of unique/primary key

为什么我会收到此错误?如果您需要任何信息,我将提供进一步的信息.

Why I am getting this error? I will provide further information if you need any.

如何解决?

编辑我在表中没有主键,但是我发现这个奇怪的索引我不记得自己添加了:

Edit I have no primary key in the table, but I found this weird index that I don't remember I had added:

索引名称= SYS_C0040476具有相同的列

index name = SYS_C0040476 which have the same columns

您可以查询 ALL_CONSTRAINTS性能视图,以查看索引所使用的约束,以及索引所应用于的表,例如:

You can query the ALL_CONSTRAINTS performance view to see which constraint the index is used by, and which table it applies to, e.g:

select owner, constraint_name, constraint_type,
    table_name, index_owner, index_name
from all_constraints
where index_name = 'PK_CHARGES';

我希望表名是'CHARGES',约束名要与索引名匹配,约束类型是'P'.但是由于您已经有了一个表格,所以名称可能没有遵循有用的约定.也许表的旧版本已被重命名,这将使约束不受新名称的影响(例如CHARGES_BACKUP之类的东西).

I would expect the table name to be 'CHARGES', the constraint name to match the index name, and the constraint type to be 'P'. But since you have a table in mind, perhaps the names aren't following a helpful convention. Maybe an old version of the table was renamed, which would leave the constraints against the new name (e.g. CHARGES_BACKUP or something).

您说您单击了表格,然后单击了视图.也许您不是在查看约束/索引所在的表.或者您正在查看实际表格上方的视图.您还要在同一列上提到一个SYS_索引-不能在同一表上.您是否有多个相似的表,或访问多个架构?您也应为该索引运行上面的查询.如上所述,您可能会找到该表的旧版本.

You said you click on the table, then on the view. Perhaps you're not looking at the table that the constraint/index is on; or perhaps you're looking at a view on top of the actual table. You also mention a SYS_ index on the same columns - which can't be on the same table. Do you have multiple similar tables, or access to multiple schemas? You shold run the above query for that index too. As mentions above, you might find an old version (or versions) of the table.

一旦确定了约束所在的表,就需要确定是否实际上应保留约束,如果没有,则可以通过使用ALTER TABLE命令删除约束来将其删除.

Once you've identified which table the constraint is on, you'll need to decide whether you should actually be keeping it, and if not you can remove it by dropping the constraint with an ALTER TABLE command.