1、oracle创建表空间
1》临时表空间
SQL> create temporary tablespace tts1
tempfile '/home/oracle/oracledata/tdbf1.dbf'
size 500m
autoextend on next 100m
extent management local;
Tablespace created.
SQL> select tablespace_name from dba_temp_files;
TABLESPACE_NAME
--------------------------------------------------------------------------------
TEMP
TTS1
2》永久表空间
SQL> create tablespace ts1
datafile '/home/oracle/oracledata/dbf1.dbf'
size 500m
autoextend on next 100m
maxsize 10g
permanent
extent management local;
Tablespace created.
SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
--------------------------------------------------------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS
TS1
2、修改表空间的名字:alter tablespace oldname rename to newname
3、设置表空间的读写状态:alter tablespace name read only/read write
4、设置数据库的默认表空间:alter database default tablespace name2
5、设置用户默认的表空间:create user name1 identified by password default tablespace name2 temporary tablespace name3
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1、数据库的对象:表、视图、索引、序列和同义词
2、约束分为标记约束和劣迹约束,常见的约束有union , check , primary key , unique , foreign key
create table t1(
id number(10) primary key,
name varchar2(100) not null,
cardnum number(10) unique
);
create table t2(
id number(10) constraint pkc2 primary key,
name varchar2(100) not null,
cardnum number(10) unique
);
create table t3(
id number(10) ,
name varchar2(100) not null,
cardnum number(10) unique,
constraint pkc3 primary key(id)
);
3、对表的修改
1》增加表的列:alter table name add column cname type cons / alter table name add constraint tname type(column) ;
2》修改表的列:alter table name modify column cname type cons;
3》删除表的列:alter table name drop column cname;
4》重命名表的列:alter table name rename column oldname to newname;
5》删除表:drop table name {cascade constraints / restrict};
4、创建序列(序列的连个属性:nextval , currval)
create sequence sq1
increment by 1
start with 0
maxvalue 10000000
minvalue 0
nocycle
nocache
5、重置序列
alter sequence sq1 increment by -1;
select sq1.NEXTVAL from dual;
alter sequence sq1 increment by 1;
select sq1.NEXTVAL from dual;
6、创建视图
create or replace view sv1
as
select keyword from sogou500w where rownum<100
with check option constraint name
with read only(默认可读可写);
7、修改视图的定义之后,依赖于该视图的所有视图都变为invalid状态;如果基础表发生变化,视图会失效,变为invalid状态,要使用alter view sv1 compile来重新编译视图。
8、伪列(rowid),索引条目(索引列值+rowid)
9、索引类型:单列索引(基本的)、复合索引、B-tree索引、位图索引、反向索引(基于B-tree)、倒序索引、函数索引
10、创建索引
create {unique / bitmap} index name
on tablename(c1,c2...)
tablespace tpname
PCTFREE number
nologging
online/noline
nosort/onsort
--创建B树索引,单列
CREATE INDEX idx_emp_name ON emp(name);
--创建复合索引
CREATE INDEX idx_emp_nameid ON emp(name,emp_id);
--创建位图索引
CREATE BITMAP INDEX idx_emp_name ON emp(name);
--创建函数索引
CREATE INDEX idx_emp_name ON emp(UPPER(name));
11、B-tree树存储结构:(索引头+键值+rowid),适合重复度较低的列,不适合重复度高的情况;原理:一个键值对应一个rowid;
12、位图存储结构:(键值+start rowid+end rowid+bit),适合重复度较高的列,不适合重复率低或者经常执行DML操作的列;原理:一个键值对应一个rowid区间;