SQL语句(二)

1.Oracle表的类型

普通表:平时使用的表,数据以无序方式进行存储。

聚簇表:一个聚簇由多个表组成,几个表共享相同的数据块。一个聚簇由一个或者多个公共的列,多个表共享这些列,这样的列叫做聚簇关键字。Oracle把多个表的数据物理地存储在一起,以加速表的连接(join),这是聚簇的优点。

        只有创建聚簇后,才能在聚簇上建立表,在往聚簇表中插入数据之前,必须在聚簇上创建聚簇索引。

        建立聚簇表的目的是为了加快查询,不是为了修改,频繁修改的表不适合使用聚簇表。

外部表:数据库仅仅存放外部表的定义,外部表的数据存放在数据库之外。其实,外部表的数据存放在操作系统的文件中。创建外部表的SQL语句分为两部分:一是描述列的定义,二是描述外部数据源如何映射成数据库的列。创建外部表时,要指定访问驱动,访问驱动用于把外部数据读入oracle。oracle提供两种驱动:oracle_loader和oracle_datapump。外部表是只读的。

临时表:表中的数据是临时的,仅仅存在一次会话或者一个事务中,而临时表的定义永久存在数据字典中。

        创建语句:create global temporary table

索引组织表:它将索引和表的数据存储在一起。普通表以无序(heap)的方式存放数据,而索引组织表按照主键进行排序,以二叉树的形式对表的数据进行存储。二叉树中的每个索引条目用<主键值,非主键值>来表示。索引组织表不存储ROWID,它通过主键来访问数据。

        普通的索引条目仅仅包含索引值和指向数据行的ROWID,而索引组织表的索引条目包含索引值和索引数据。

        有时候,表的数据很大,以致于一个索引条目不能够容纳,oracle将一条记录分成两部分:

        一是索引部分,存放主键值、频繁访问的部分非主键值、指向溢出区的ROWID。

        二是溢出区,存放在一个溢出表空间中。

哑表(dual):是创建数据库的时候,Oracle自动创建的一张表,属于SYS用户,该表有一列DUMMY组成,且该表只存储一条记录。

2.创建表

1.创建普通表
create table tb_ordernary 
(
    id number not null primary key,
    name varchar2(20) default 'os',
    address varchar2(40)
)
tablespace myspace
storage
    (
        initial 64k                 --指定初始区的大小
        next  1M                    --指定下一个区的大小
        minextents 1                --指定最少要分配多少个区
        maxextents unlimited        --指定去的最大数量
    )
1.创建聚簇
create cluster tb_cluster (postcode int)
tablespace myspace;

2.表添加到聚簇
create table student (
    id int primary key,
    name varchar2(20) not null,
    postcode int
)
cluster tb_cluster(postcode);

3.另外一个表加入聚簇
create table address_infor (
    postcode int primary key,
    name varchar2(40) not null,
    detail varchar2(40)    
)
cluster tb_cluster (postcode);
1.创建索引组织表
create table students (
    name varchar(20) primary key,     --一定要有主键
    id number,                        
    detail varchar2(100)
)
organization index                    --索引组织表
tablespace users                      
pctthreshold 30                       --指定溢出的比例
including detail                      --指定列名,从这个列以后的所有列都将存储在溢出区
overflow tablespace myspace ;         --指定溢出表空间
1.创建事务型临时表
create global temporary table gtt1
(
    name varchar2(20),
    id number,
    birthday date
)on commit delete rows;                ---事务型临时表


2.创建会话型临时表
create global temporary tabe gtt2
(
    name varchar2(20),
    id number,
    birthday date
) on commit preserve rows;             ---会话型临时表

3.克隆表

    创建一个一样的表,叫做克隆表

1.仅仅克隆表,结构一样
create table t_clone1 
as select * from stb
where 1=0 ;

2.克隆表,数据也包含进去
create table t_clone2
as select * from stb;

4.修改表

1.添加新列
alter table tb add (lenth number(8,3));

2.列重命名
alter table tb rename column lenth to new_lenth ;

3.改变列的属性
alter table tb modify (new_lenth number(4,1)) ;
alter table tb modify (new_lenth default 5);
alter table tb modify (new_lenth not null);
alter table tb modify (new_lenth encrypt using '3des168');
alter table tb modify (new_lenth decrypt);

4.删除列
alter table tb drop (new_lenth,address);

5.为表手工分配一个新的区
alter table tb allocate extent (size 50k);

6.把表移动到一个新的段
alter table tb 
move storage
(
    initial 20k
    next 40k
    minextents 2
    maxextents 20
    pctincrease 0
);

7.把表移动到其他表空间
alter table tb move tablespace myspace2 ;

 

 

 

 

 

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值