首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

四、模式对象管理 (table,index,seq)

2012-07-23 
4、模式对象管理 (table,index,seq)这里说的模式对象:表,索引,约束,视图,同义词,序列。模式是一个数据库对象

4、模式对象管理 (table,index,seq)
这里说的模式对象:表,索引,约束,视图,同义词,序列。
模式是一个数据库对象的集合,为一个数据库用户所有,并且具有与该用户相同的名称。
模式对象是由用户创建的逻辑结构,用来包含或引用他们的数据。
1.管理表
第一、创建表

create table user.table_name    --用户名.表名({column1 datatype               --列名,类型   [default expr]               --默认值,   [column_constraint]},        --约束{[column2 datatype ]...})[constraint table_constraint]   --表间约束[cluster cluster1 (column1,column2,...)] --聚合?[pctfree n]                     --如果数据库剩余的自由空间少于pctfree自由空间,也就是说数据库已经写满,那么数据库就不会对其进行插入操作 [pctused n]                     --每个update和delete操作后,数据库会比较该数据块的已用空间和pct_used,如果少于pct_used的已用空间,那么这个数据块被加入到自由列表中,供insert使用[storage n]                     --inital 初始大小,next 下一次大小,minextents 最小分配数,maxextents 最大分配数,pctincrease 增长百分比[tablespace tbs]                --表空间[enable|disable][as query]                      --在查询的时候创建列:create table tab_01 nologging compress tablespace tempas select * from tab_02 where 1=1 and ...;

查看表创建信息。
select owner,table_name,tablespace_name,initial_extent from dba_tables where owner ='scott';

第二、修改表结构
alter table tab_01 add(addName varchar2(30));--添加列alter table tab_01 modify(addName varchar2(100));--修改列alter table tab_01 rename column addName to delName;--修改列名alter table tab_01 drop column delName;--删除列rename tab_01 to tab_02;      --重命名表alter table tab_02 to tab_01; --重命名表drop table tab_01[cascade constraints]; --删除表,包括约束---------------------------------------------------------修改表空间的存储位置使用alter table ... move ...重定位非分区表的数据到新的段中。alter table tab_01 move storage (initial 20K   next 40K   minextents 2  maxextents 20)

第三、监控表的存储空间
--1.对表进行分析统计analyze table tab_01 compute statistics;--2.估计统计analyze table tab_01 estimate statistics;--3.分析指定行记录样本analyze table tab_01 estimate statistics sample 2000 rows;--4.分析百分比样本analyze table tab_01 estimate statistics sample 80 percent;--5.删除统计数据analyze table tab_01 delete statistics;--6.查询分析结果select table_naem ,num_rows,blocks,empt_blocks from dba_tables where table_name ='tab_01';

第四、外部表
外部表的作用?
------------------------------------
2.索引
索引在物理和逻辑上依赖于表的数据,作为独立的结构,需要存储空间的支持。在插入,更新,删除表中的数据时,数据库将自动维护索引
维护建议:
在插入数据后创建索引。
为提高性能,为索引列排序
限制每个表索引的数量
为每个索引表定义表空间
考虑创建并行索引 --????
--默认索引 B-tree索引--创建索引create index tab_index on tab_01 (tab_No,tab_Name) tablespace index_tbs;--重建索引ALTER INDEX tab_index rebuild online;-----------------------oracle 提供了监控索引的方式能够确定是否被使用,这个要在实战中学习。

3.视图
create or replace view tab_view as select t01.tab_No,t01.tab_name,t02.tab_agefrom tab_01 t01 ,tab_02 t02where t01.tab_No = t02.tab_no;

4.序列
--创建create sequence tab_seq increment by 1 start with 1nomaxvalue nocycle cache 0;--修改alter sequence tab_seqincrement by 10 maxvalue 10000cycle cache20;--删除drop sequence tab_seq;

热点排行