ORACLE SQL总结三:DDL语句(一)

2014-11-24 16:54:08 · 作者: · 浏览: 2

ORACLE SQL总结三:DDL语句
5、DDL语句
5.1 Enable/Disable/Validate/Novalidate 组合特性说明:
www.2cto.com
是否要求满足约束 Validate Novalidate
已有记录 新增/修改记录 已有记录 新增/修改记录
Enable Yes Yes No Yes
Disable Yes No No No
Validate确保已有数据符合约束;
Novalidate不必考虑已有数据是否符合约束。
除非Novalidate被指定,Enable默认Validate;
除非Validate被指定,Disable默认Novalidate;
Validate和Novalidate对Enable和Disable没有任何默认暗示。
Enable Validate与Enable相同,检查已有记录和新增记录,确保都符合约束;
Enable Novalidate 允许已有记录不必满足约束条件,但新增/修改的记录必须满足;
Disable Validate禁用约束,删除约束上的索引,不允许修改任何被约束的记录;
Disable Novalidate与Disable相同,禁用约束,删除约束上的索引,且允许修改被约束的记录。
详细参考sql references
5.2 关于partition表的疑问
Partitioning allows a table, index, or index-organized table to be subdivided into smaller pieces, where each piece of such a database object is called a partition. Each partition has its own name, and may optionally have its own storage characteristics.
partitioning允许表、索引、或索引组织表切分成更小的片,每片称为partition,每个partition有自己的name,并可以有自己的存储特性。
www.2cto.com
oracle手册上也说partition的优点是可以并行访问分区(因为每个分区表可以放在不同的硬盘上),这样可以提升性能。
那么我的问题来了,如果我只有一块硬盘,那么所有的partition 表就只能放在这一块硬盘上,是不是即使做了partition表也不能提升性能呢?
5.3 索引和索引-组织表
索引的类型:
(1)B-TREE索引,又分为:
索引-组织表
反序键索引
倒序索引
B-TREE集群索引
(2)Bitmap 索引
(3)Function-based 索引
(4)应用域索引
www.2cto.com
《oracle concept》关于索引描述得很详细,翻译部分内容
**************
An index is an optional structure, associated with a table or table cluster, that can sometimes speed data access. By creating an index on one or more columns of a table, you gain the ability in some cases to retrieve a small set of randomly distributed rows from the table. Indexes are one of many means of reducing disk I/O.
一个索引是一个可选的于表和表簇有关系的数据结构,它有时可以加快数据访问速度。通过在一个或多个列上产生一个索引,你可以提升访问以随机方式存储的数据的能力,索引是多种减少硬盘I/O操作的方式之一。
If a heap-organized table has no indexes, then the database must perform a full table scan to find a value. For example, without an index, a query of location 2700 in the hr.departments table requires the database to search every row in every table block for this value. This approach does not scale well as data volumes increase.
如果一个heap-organized table(oracle create table 时默认这种方式), 数据库必须执行全表扫描来查找一个数据。例如,如果没有索引,在hr.departments表中查询location=2700,就必须搜索表中每个块(block),这种方式随着数据的增加性能更加糟糕。
www.2cto.com
For an analogy, suppose an HR manager has a shelf of cardboard boxes. Folders containing employee information are inserted randomly in the boxes. The folder for employee Whalen (ID 200) is 10 folders up from the bottom of box 1, whereas the folder for King (ID 100) is at the bottom of box 3. To locate a folder, the manager looks at every folder in box 1 from bottom to top, and then moves from box to box until the folder is found. To speed access, the manager could create an index that sequentially lists every employee ID with its folder location:
ID 100: Box 3, position 1 (bottom)
ID 101: Box 7, position 8
ID 200: Box 1, position 10
.
假设一种情形,一个HR经理有一个装满卡片箱子的书架,收藏着雇员信息的文件夹被随机地放在盒子里,每个盒子里有10个文件夹,雇员Whalen(ID 200)的文件夹被放在第1个盒子的顶部,雇员King(ID 100)的文件夹被放在第1个盒子的底部,HR经理必须从顶到底地查询每个盒子里的文件夹,并且逐个逐个地查询盒子,直到找到所需的文件夹。为了加快查询速度,经理可以做一张表,表上顺序第列出每个雇员ID和他的文件夹所放的位置。
Bitmap In