oracle语法细节备忘2

1. 查看某个表的约束

    select owner, constraint_name from user_constraints where table_name = 'TEST'

    涉及三个视图all_constraints / use_constraints/ dba_constraints

 

2. 查看某个表字段的约束

    select * from user_cons_columns where table_name = 'TEST';

    也涉及三个视图 all_cons_columns/ user_cons_columns/ dba_cons_columns/

 

3. 添加约束

    alter table test       

     add unique(empno);

 

4. 删除约束

     alter table test
      drop constraint SYS_C0010827

 

5. 添加约束的同时赋予名字

      alter table test
       add constraint uni_123123 unique(comm); 

 

6. 禁用约束

      alter table test
      disable constraint uni_123123;

      如果是禁用的主键约束, 需要先将引用这个表的其它表的外键禁用

 

7, 启用约束

      alter table test
      enable constraint uni_123123;

 

8. 创建唯一索引

      create unique index test_comm_u on test(comm);

 

9. 创建位图索引

      create bitmap index test_sex on test(sex); 

    位图索引常使用在内容单一的列上, 如性别等

 

10. 重建索引

      alter index test_sex
      rebuild

 

11. 合并索引

      alter index test_sex coalesce;

 

12. 删除索引

      drop index test_sex

 

13. 查看用户的索引

      select index_name, table_name from user_indexes

 

14. 查看用户的索引的字段

      select index_name , column_name from user_ind_columns

你可能感兴趣的:(oracle)