表空间,索引

来源:互联网 发布:淘宝店铺装修模版 编辑:程序博客网 时间:2024/05/29 10:13
表空间
为什么要创建表空间?是为了便于管理,毕竟逻辑存储结构相对于物理存储结构来说,软件管理的可用性会大大提高。比如扩容、改删、迁移等。以下摘自《数据库系统概念》第五版:表空间也可以作为在数据库之间转移数据的一种办法。譬如,很常见的是每隔一段时间把数据从事务系统转移到数据仓库中去。Oracle允许将一个表空间的所有数据从一个系统转移到另一个系统,仅仅简单地复制文件并从数据字典元数据中输入输出一小部分数据。这些操作比从一个数据库下载数据,然后用一个加载器将数据插入到另一个数据库中比起来块多了。
2012-12-31更新(描述清楚点):
1、表空间是逻辑结构,对开发人员或者用户来说处理逻辑结构更方便、对系统管理员来说逻辑结构不可见,更能保证数据安全性,物理结构则交由数据库本身去管理,这样在重新组织物理存储后(如迁移、更换硬件、更换操作系统)应用程序可以不做任何修改直接使用。
2、如果没有表空间,庞大的数据库系统中的表、索引等会对应于相应数量的操作系统文件,这对DBA的维护工作来说是无法想象的。
3、表空间的逻辑结构可以突破操作系统或者底层硬件环境(如硬盘大小)对文件大小的限制,
创建表空间
表空间  建立表空间(一般建N个存数据的表空间和一个索引空间):  create tablespace 表空间名  datafile ' 路径(要先建好路径)\***.dbf  ' size *M  tempfile ' 路径\***.dbf ' size *M  autoextend on  --自动增长  --还有一些定义大小的命令,看需要   default storage(   initial 100K,   next 100k,  ); 
例子:创建表空间  create tablespace DEMOSPACE   datafile 'E:/oracle_tablespaces/DEMOSPACE_TBSPACE.dbf'   size 1500M   autoextend on next 5M maxsize 3000M;  删除表空间  drop tablespace DEMOSPACE including contents and datafiles  

-- Create table
create table O_ORG
(
  org_no       VARCHAR2(16 CHAR) not null,
  org_name     VARCHAR2(256 CHAR),
  p_org_no     VARCHAR2(16 CHAR),
  org_type     VARCHAR2(8 CHAR),
  sort_no      NUMBER(5),
  org_default  VARCHAR2(32),
  is_org_ims   VARCHAR2(8),
  org_no_icss  VARCHAR2(16 CHAR),
  p_org_no_ics VARCHAR2(16 CHAR),
  org_no_isc   VARCHAR2(256 CHAR)
)
tablespace DATA_ICS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
-- Add comments to the table 
comment on table O_ORG
  is '1) 供电单位的基本信息,供电单位为独立的考核单位,如:地市局、分局、供电所。
本实体主要包括单位标识、单位名称、上级单位标识、单位类型、排序序号等属性。
2) 通过供电单位管理,由录入产生记录。
3) 该实体主要由供电单位管理、部门管理使用。
4) 如果采用第三方组件,则本实体可以转换为视图,供其他数据域实体引用。
';
-- Add comments to the columns 
comment on column O_ORG.org_no
  is '本实体记录的唯一标识,创建供电单位的唯一编码。';
comment on column O_ORG.org_name
  is '供电单位详细的名称。';
comment on column O_ORG.p_org_no
  is '直接上级供电单位编号。';
comment on column O_ORG.org_type
  is '单位类别:国网公司、省公司、地市公司、区县公司、分公司、供电所等。01 国网公司、02 省公司、03 地市公司 、04 区县公司、05 分公司、06 供电所。';
comment on column O_ORG.sort_no
  is '在同级中的排列顺序的序号,用自然数标识,如,1、2、3。';
comment on column O_ORG.org_default
  is '客户信息维护时的默认单位,默认值设置为1';
comment on column O_ORG.is_org_ims
  is '是否运维人员维护的单位:1-是;0-否;';
comment on column O_ORG.org_no_icss
  is 'ICS的单位编码';
comment on column O_ORG.p_org_no_ics
  is 'ics的上级单位编码';
comment on column O_ORG.org_no_isc
  is 'isc对应的单位编码(主要给省级单位编码做对照)';
-- Create/Recreate indexes 

创建唯一索引(姓名不能重复)create unique  index  username_index  ON  t_user (username);创建组合索引create index name_time_index  ON  t_user(username,user_time);


create index IDX_O_ORG_ORGNO_ICS on O_ORG (ORG_NO_ICSS)  tablespace DATA_ICS  pctfree 10  initrans 2  maxtrans 255  storage  (    initial 64K    minextents 1    maxextents unlimited  );create index IDX_O_ORG_P_ORG_NO on O_ORG (P_ORG_NO)  tablespace DATA_ICS  pctfree 10  initrans 2  maxtrans 255  storage  (    initial 64K    minextents 1    maxextents unlimited  );-- Create/Recreate primary, unique and foreign key constraints alter table O_ORG  add constraint P_O_ORG primary key (ORG_NO)  using index   tablespace DATA_ICS  pctfree 10  initrans 2  maxtrans 255  storage  (    initial 64K    minextents 1    maxextents unlimited  );







原创粉丝点击