Oracle创建索引
1、创建索引
create index 索引名 on 表名(列名);
-- 声明表空间
create index 索引名 on 表名(列名) online tablespace 空间名;
create index 索引名 on 表名(列名) tablespace 表空间名;
2、删除索引
drop index 索引名;
3、创建组合索引
create index 索引名 on 表名(列名1,列名2,...);
4、创建唯一索引
create unique index 索引名 on 表名(列名);
5、创建反向键索引
create index 索引名 on 表名(列名) reverse;
6、创建位图索引
create bitmap index 索引名 on 表名(列名);
7、创建基于函数的索引
create index 索引名 on 表名(函数名) tablespace 表空间名;
例如:
create index sname_index on student2(upper(sname)) tablespace users;
8、查询索引
--根据索引名,查询表索引字段
select * from user_ind_columns where index_name='索引名';
--根据表名,查询一张表的索引
select * from user_indexes where table_name='表名';
9、查看索引
-- oracle
SELECT * FROM ALL_INDEXES WHERE TABLE_NAME='XXXXX';
-- mysql
SHOW INDEX FROM TABLE_NAME
补充:
-- MySQL创建索引
ALTER TABLE 表名 ADD INDEX 索引名(列名);
-- MySQL删除索引
ALTER TABLE 表名 DROP INDEX 索引名;
删除索引的方式取决于你创建的方式。如果使用create index方式创建,那么直接drop index就可以删除。如果是用alter,那么删除也用alter。