问题描述
请考虑以下两个表及其主键:
请注意,我的索引的名称与主键的名称相同: test2_pk。
如果我比较一下约束条件和索引,我看不出“自动”索引之间有什么区别test1_pk 和“手动”索引test2_pk.
但显然,先知can告诉他们区别,因为如果我现在删除主键并再次检查我的索引:
“自动”索引test1_pk已经不在了,但是“手动”索引test2_pk 仍然在这里(因为它应该在这里)
我的问题是:How can I know if an index is "automatic" (i.e. will be dropped when dropping the primary key) or "manual" (won't be dropped when dropping the primary key) ?
create table testuser.test1 (
col1 number not null,
col2 number not null,
col3 number not null
);
alter table testuser.test1
add constraint test1_pk primary key (col1);
create table testuser.test2 (
col1 number not null,
col2 number not null,
col3 number not null
);
create unique index testuser.test2_pk on testuser.test2 (col1);
alter table testuser.test2
add constraint test2_pk primary key (col1)
using index testuser.test2_pk;
请注意,我的索引的名称与主键的名称相同: test2_pk。
如果我比较一下约束条件和索引,我看不出“自动”索引之间有什么区别test1_pk 和“手动”索引test2_pk.
select * from dba_indexes where table_owner = 'TESTUSER' and lower(index_name) like '%test%'; select * from dba_constraints where owner = 'TESTUSER' and lower(constraint_name) like '%test%';
但显然,先知can告诉他们区别,因为如果我现在删除主键并再次检查我的索引:
alter table testuser.test1 drop constraint test1_pk; alter table testuser.test2 drop constraint test2_pk; select * from dba_indexes where table_owner = 'TESTUSER' and lower(index_name) like '%test%';
“自动”索引test1_pk已经不在了,但是“手动”索引test2_pk 仍然在这里(因为它应该在这里)
我的问题是:How can I know if an index is "automatic" (i.e. will be dropped when dropping the primary key) or "manual" (won't be dropped when dropping the primary key) ?
专家解答
它在标准视图中不可见。(您可以通过查看支持这些视图的表中的数据来了解差异).
因此,当您想要删除约束时,您可以使用“保留索引”和“删除索引”子句来进行自己的显式控制,而不是查询它是否会这样做。
因此,当您想要删除约束时,您可以使用“保留索引”和“删除索引”子句来进行自己的显式控制,而不是查询它是否会这样做。
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




