SQL>alter table books rename constraint pk_books to pk_books_id;
约束校验的时机
延迟约束 deferred constraint :约束在提交的时候进行校验。
1)deferrable :说明约束是否可以被延迟,添加该选项说明可以被延迟。
2)initially deferred 或者 initially immediate:说明约束创建时候,何时校验数据。
initially deferred :提交校验。设置该选项必须设置了deferrable。
initially immediate:默认值,立即校验。
SQL>alter table sales add constraint chk_sales check(price*qty=value) deferrable initially deferred;
SQL>alter session set constraint=deferred;
当发出该语句之后,说明当前session中,对于发出的所有DML语句所涉及的表,只要这些表上约束定义了deferrable选项,这些约束全部延迟检验。
5、使用分区表,索引组织表,簇表
Oracle 10g 提供五种分区的方法
1)范围分区 Range Partition
create table t2(id number,createdate date)
partition by range(createdate)
(
partition p1 values less than (to_date('2001-01-01','yyyy-mm-dd')) tablespace ts01,
partition p2 values less than (to_date('2002-01-01','yyyy-mm-dd')) tablespace ts02,
partition p3 values less than (to_date('2003-01-01','yyyy-mm-dd')) tablespace ts03,
partition pmax values less than (maxvalue) tablespace ts04
);
2)哈希分区 Hash Partition
create table t3(id number,name varchar2(10))
partition by hash(id)
partitions 4
store in (ts01,ts02.ts03.ts04);
create table t3(id number,varchar2(10))
partition by hash(id)
(
partition p1 tablespace ts01,
partition p2 tablespace ts02,
partition p3 tablespace ts03,
partition p4 tablespace ts04
):
3)列表分区 List Partition
create table t4(id number,name varchar2(10),category varchar2(10))
partition by list(category)
(
partition p1 values ('01','02') tablespace ts01,
partition p2 values ('03','04') tablespace ts02,
partition p3 values ('05','06','07') tablespace ts03,
partition p4 values (default) tablespace ts04,
);
4)范围哈希组合分区 Range-Hash Partition
create table t5(id,number,name varchar2(10),createdate date)
partition by range (createdate)
subpartition by hash (id)
subpartitions 4 store in (ts01,ts02)
(partition p1 values less than (to_date('2001-01-01','yyyy-mm-dd')),
partition p2 values less than (to_date('2002-01-01','yyyy-mm-dd')),
partition p3 values less than (to_date('2003-01-01','yyyy-mm-dd')),
partition pmax values less than (maxvalue)
subpartitions 2 store in (ts03) );
说明:先按createdate进行范围分区,然后再按照id进行hash分区。默认每个分区包含4个hash子分区,这些子分区都分别在ts01和ts02里。
也是就是p1,p2,p3都是如此,但对于pmax来说,修改了默认设置,pmax有两个hash分区,都位于ts03里。
5)范围列表组合分区 Range-List Partition
create table t6(id number,name varchar2(10),category varchar2(10),createdate date)
partition by range(createdate)
subpartition by list (category)
(partition p1 values less than (to_date('2001-01-01','yyyy-mm-dd')) tablespace ts01
(subpartition p1_1 values ('01','02'),
subpartition p1_2 values ('03','04'),
subpartition p1_3 values (default) tablespace ts02),
partition p2 values less than (maxvalue) tablespace ts03
(subpartition p1_1 values ('01','02'),
subpartition p1_2 values ('03','04'),
subpartition p1_3 values (default) tablespace ts04)
);
索引组织表 index organized table