oracle中约束和索引的前后关系
来源:互联网 发布:远程wifi控制软件 编辑:程序博客网 时间:2024/05/16 07:42
增加唯一性约束会自动创建唯一性索引:
SQL> create table t (c1 number, c2 varchar2(30));
Table created.
SQL> alter table t add constraint uk_t_c1 unique (c1);
Table altered.
SQL> select index_name from user_indexes where table_name = 'T';
INDEX_NAME
------------------------------
UK_T_C1
SQL> select constraint_name from user_constraints where table_name = 'T';
CONSTRAINT_NAME
------------------------------
UK_T_C1
删除约束也会自动把相应的所以删除:
SQL> alter table t drop constraint uk_t_c1;
Table altered.
SQL> select index_name from user_indexes where table_name = 'T';
no rows selected
SQL> select constraint_name from user_constraints where table_name = 'T';
no rows selected
除非删除约束时加上keep index以保留索引:
SQL> alter table t add constraint uk_t_c1 unique (c1);
Table altered.
SQL> alter table t drop constraint uk_t_c1 keep index;
Table altered.
SQL> select index_name from user_indexes where table_name = 'T';
INDEX_NAME
------------------------------
UK_T_C1
SQL> select constraint_name from user_constraints where table_name = 'T';
no rows selected
SQL> drop index uk_t_c1;
Index dropped.
SQL> select index_name from user_indexes where table_name = 'T';
no rows selected
但是如果先建立了索引再建约束:
SQL> create unique index uk_t_c1 on t (c1);
Index created.
SQL> select index_name from user_indexes where table_name = 'T';
INDEX_NAME
------------------------------
UK_T_C1
SQL> alter table t add constraint uk_t_c1 unique (c1);
Table altered.
这时候删除约束的时候就不会把对应的索引删除:
SQL> alter table t drop constraint uk_t_c1;
Table altered.
SQL> select index_name from user_indexes where table_name = 'T';
INDEX_NAME
------------------------------
UK_T_C1
SQL>
如果想在删除约束时保留索引,建议还是最好明确使用keep index,以避免意想不到的问题发生。
--End--
SQL> create table t (c1 number, c2 varchar2(30));
Table created.
SQL> alter table t add constraint uk_t_c1 unique (c1);
Table altered.
SQL> select index_name from user_indexes where table_name = 'T';
INDEX_NAME
------------------------------
UK_T_C1
SQL> select constraint_name from user_constraints where table_name = 'T';
CONSTRAINT_NAME
------------------------------
UK_T_C1
删除约束也会自动把相应的所以删除:
SQL> alter table t drop constraint uk_t_c1;
Table altered.
SQL> select index_name from user_indexes where table_name = 'T';
no rows selected
SQL> select constraint_name from user_constraints where table_name = 'T';
no rows selected
除非删除约束时加上keep index以保留索引:
SQL> alter table t add constraint uk_t_c1 unique (c1);
Table altered.
SQL> alter table t drop constraint uk_t_c1 keep index;
Table altered.
SQL> select index_name from user_indexes where table_name = 'T';
INDEX_NAME
------------------------------
UK_T_C1
SQL> select constraint_name from user_constraints where table_name = 'T';
no rows selected
SQL> drop index uk_t_c1;
Index dropped.
SQL> select index_name from user_indexes where table_name = 'T';
no rows selected
但是如果先建立了索引再建约束:
SQL> create unique index uk_t_c1 on t (c1);
Index created.
SQL> select index_name from user_indexes where table_name = 'T';
INDEX_NAME
------------------------------
UK_T_C1
SQL> alter table t add constraint uk_t_c1 unique (c1);
Table altered.
这时候删除约束的时候就不会把对应的索引删除:
SQL> alter table t drop constraint uk_t_c1;
Table altered.
SQL> select index_name from user_indexes where table_name = 'T';
INDEX_NAME
------------------------------
UK_T_C1
SQL>
如果想在删除约束时保留索引,建议还是最好明确使用keep index,以避免意想不到的问题发生。
--End--
- oracle中约束和索引的前后关系
- MySQL、SQLServer、Oracle中约束和索引的关系
- ORACLE的索引和约束
- oracle的约束和索引
- Oracle的约束和索引
- Oracle的约束和索引
- oracle的约束和索引
- Oracle中唯一约束和唯一索引的区别
- Oracle中查看无效的对象、约束、触发器和索引
- ORACLE中主键约束跟唯一索引之间的关联关系
- ORACLE的索引和约束详解
- ORACLE的索引和约束详解
- ORACLE的索引和约束详解
- ORACLE的索引和约束详解
- ORACLE的索引和约束详解
- ORACLE的索引和约束详解
- ORACLE的索引和约束详解(转)
- ORACLE的索引和约束详解
- 集合框架_Collection_Set_HashSet
- JAVA集合的并发
- select模型讲解
- struts2 返回类型配置
- webkit中 html的解析及dom树和render树的生成 .
- oracle中约束和索引的前后关系
- cadence 焊盘制作
- 矩阵分解与推荐系统
- Shell脚本语法
- 二叉树的创建和遍历
- 五、总观Application Framework
- 统计整数二进制表示中1的个数
- Cocos2d-x 中游戏暂停与恢复
- Loading Large Bitmaps Efficiently [有效率的加载大尺寸的位图]