1.给表中某个字段添加非唯一索引:
create index 索引名 on 表名 (字段名) online tablespace 表空间名 nologging local;
2.给表中某个字段添加唯一索引:
create unique index 索引名 on 表名 (字段名) online tablespace 表空间名 nologging local;
3.给表字段添加主键索引:
alter table 表名
add constraint 主键名 primary key (字段名)
using index
tablespace 表空间名
pctfree 10 --表示当数据块的可用空间低于10%后,就不可以被insert了,默认值为10
initrans 2 --指的是事务表的初始大小,默认值为2条目
maxtrans 255 --指事务表的最大条目,默认值为255
storage --索引的表空间属性
(
initial 64K --索引的初始化大小
next 1M --之后每次增加的大小
minextents 1 --最小区间数量
maxextents unlimited --最大区间数量,不设限制
);
4.给表添加联合主键索引:
alter table 表名
add constraint 主键索引名 primary key (字段1, 字段2)
using index
tablespace 表空间名
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);
5.创建自增序列:
CREATE SEQUENCE 序列名
INCREMENT BY 1 --每次自增几
START WITH 1 --从几开始
NOMAXVALUE --无限
NOCYCLE --不循环
CACHE 200; --缓存指定个数的序列值, 默认20 ,过小会导致CPU占用过高.
6.获取序列值:
SELECT 序列名.NEXTVAL FROM DUAL