Gforge 发表于 2011-12-23 01:57

Oracle数据库对象—同义词

<span class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 25px; background-color: rgb(255, 255, 255); "><span lang="EN-US" style="line-height: 37px; "><font class="Apple-style-span" color="#808000">转:http://cuiguoqiang.blog.163.com/blog/static/119597106200962015237746/</font></span></span><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 25px; background-color: rgb(255, 255, 255); "><span lang="EN-US" style="line-height: 37px; ">1&nbsp;</span><span style="line-height: 37px; font-family: 黑体; ">同义词的概念</span><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span lang="EN-US" style="line-height: 25px; ">Oracle</span><span style="line-height: 25px; font-family: 宋体; ">数据库中提供了同义词管理的功能。同义词是数据库方案对象的一个别名,经常用于简化对象访问和提高对象访问的安全性。在使用同义词时,</span><span lang="EN-US" style="line-height: 25px; ">Oracle</span><span style="line-height: 25px; font-family: 宋体; ">数据库将它翻译成对应方案对象的名字。与视图类似,同义词并不占用实际存储空间,只有在数据字典中保存了同义词的定义。在</span><span lang="EN-US" style="line-height: 25px; ">Oracle</span><span style="line-height: 25px; font-family: 宋体; ">数据库中的大部分数据库对象,如表、视图、同义词、序列、存储过程、包等等,数据库管理员都可以根据实际情况为他们定义同义词。</span></p><span lang="EN-US" style="line-height: 37px; ">2&nbsp;</span><span style="line-height: 37px; font-family: 黑体; ">同义词的分类</span><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span lang="EN-US" style="line-height: 25px; ">Oracle</span><span style="line-height: 25px; font-family: 宋体; ">数据库同义词有两种类型,分别是公用同义词与私有同义词:</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span style="line-height: 25px; font-family: 宋体; ">公用同义词由一个特殊的用户组</span><span lang="EN-US" style="line-height: 25px; ">Public</span><span style="line-height: 25px; font-family: 宋体; ">所拥有。顾名思义,数据库中所有的用户都可以使用公用同义词。公用同义词往往用来标示一些比较普通的数据库对象,这些对象往往大家都需要引用。</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span style="line-height: 25px; font-family: 宋体; ">私有同义词是跟公用同义词所对应,他是由创建他的用户所有。当然,这个同义词的创建者,可以通过授权控制其他用户是否有权使用属于自己的私有同义词。</span></p><span lang="EN-US" style="line-height: 37px; ">3&nbsp;</span><span style="line-height: 37px; font-family: 黑体; ">同义词的创建及删除</span><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span style="line-height: 25px; font-family: 宋体; ">创建公有同义词的语法:</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">Create synonym&nbsp;</span><span style="line-height: 25px; font-family: 宋体; ">同义词名称</span><span lang="EN-US" style="line-height: 25px; ">&nbsp;for objectName;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">Drop synonym&nbsp;</span><span style="line-height: 25px; font-family: 宋体; ">同义词名称</span></p><span lang="EN-US" style="line-height: 37px; ">4</span><span style="line-height: 37px; font-family: 黑体; ">同义词的作用</span><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">(1)&nbsp;</span><span style="line-height: 25px; font-family: 宋体; ">多用户协同开发中,可以屏蔽对象的名字及其持有者。</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span style="line-height: 25px; font-family: 宋体; ">如果没有同义词,当操作其他用户的表时,必须通过</span><b style="line-height: 25px; "><span lang="EN-US" style="line-height: 25px; ">user</span></b><b style="line-height: 25px; "><span style="line-height: 25px; font-family: 宋体; ">名</span><span lang="EN-US" style="line-height: 25px; ">.object</span></b><b style="line-height: 25px; "><span style="line-height: 25px; font-family: 宋体; ">名</span></b><span style="line-height: 25px; font-family: 宋体; ">的形式,采用了同义词之后就可以隐蔽掉</span><span lang="EN-US" style="line-height: 25px; ">user</span><span style="line-height: 25px; font-family: 宋体; ">名,当然这里要注意的是:</span><span lang="EN-US" style="line-height: 25px; ">public</span><span style="line-height: 25px; font-family: 宋体; ">同义词只是为数据库对象定义了一个公共的别名,其他用户能否通过这个别名访问这个数据库对象,还要看是否已经为这个用户授权。</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">(2)&nbsp;</span><span style="line-height: 25px; font-family: 宋体; ">为用户简化</span><span lang="EN-US" style="line-height: 25px; ">sql</span><span style="line-height: 25px; font-family: 宋体; ">语句。</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span style="line-height: 25px; font-family: 宋体; ">上面的一条其实就是一种简化</span><span lang="EN-US" style="line-height: 25px; ">sql</span><span style="line-height: 25px; font-family: 宋体; ">的体现,同时如果自己建的表的名字很长,可以为这个表创建一个同义词来简化</span><span lang="EN-US" style="line-height: 25px; ">sql</span><span style="line-height: 25px; font-family: 宋体; ">开发。</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">(3)</span><span style="line-height: 25px; font-family: 宋体; ">为分布式数据库的远程对象提供位置透明性。</span></p><span lang="EN-US" style="line-height: 37px; ">5&nbsp;</span><span style="line-height: 37px; font-family: 黑体; ">同义词在数据库链中的作用</span><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span style="line-height: 25px; font-family: 宋体; ">数据库链是一个命名的对象,说明一个数据库到另一个数据库的路径,通过其可以实现不同数据库之间的通信。</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">Create database link&nbsp;</span><span style="line-height: 25px; font-family: 宋体; ">数据库链名</span><span lang="EN-US" style="line-height: 25px; ">&nbsp;connect<span style="line-height: 25px; ">&nbsp;&nbsp;</span>to<span style="line-height: 25px; ">&nbsp;&nbsp;</span>user</span><span style="line-height: 25px; font-family: 宋体; ">名</span><span lang="EN-US" style="line-height: 25px; ">&nbsp;identified by&nbsp;</span><span style="line-height: 25px; font-family: 宋体; ">口令</span><span lang="EN-US" style="line-height: 25px; "><span style="line-height: 25px; ">&nbsp;&nbsp;</span>using ‘Oracle</span><span style="line-height: 25px; font-family: 宋体; ">连接串</span><span lang="EN-US" style="line-height: 25px; ">’;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span style="line-height: 25px; font-family: 宋体; ">访问对象要通过</span><span lang="EN-US" style="line-height: 25px; ">&nbsp;object</span><span style="line-height: 25px; font-family: 宋体; ">名</span><span lang="EN-US" style="line-height: 25px; ">@</span><span style="line-height: 25px; font-family: 宋体; ">数据库链名。</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span style="line-height: 25px; font-family: 宋体; ">同义词在数据库链中的作用就是提供位置透明性:</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span style="line-height: 25px; font-family: 宋体; ">例:</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span style="line-height: 25px; font-family: 宋体; ">三台服务器</span><span lang="EN-US" style="line-height: 25px; ">S1,S2,S3</span><span style="line-height: 25px; font-family: 宋体; ">,每个服务器上都装有</span><span lang="EN-US" style="line-height: 25px; ">Oracle</span><span style="line-height: 25px; font-family: 宋体; ">数据库,然后又三个表</span><span lang="EN-US" style="line-height: 25px; ">Student,Course,S_C</span><span style="line-height: 25px; font-family: 宋体; ">分别存在三台服务器的数据库中,如果一个应用要同时访问这三张表,当然首先要建立数据库链:</span><span lang="EN-US" style="line-height: 25px; ">S1</span><span style="line-height: 25px; font-family: 宋体; ">——</span><span lang="EN-US" style="line-height: 25px; ">&gt;S2</span><span style="line-height: 25px; font-family: 宋体; ">的叫</span><span lang="EN-US" style="line-height: 25px; ">DLA1, S1</span><span style="line-height: 25px; font-family: 宋体; ">——</span><span lang="EN-US" style="line-height: 25px; ">&gt;S3</span><span style="line-height: 25px; font-family: 宋体; ">的叫</span><span lang="EN-US" style="line-height: 25px; ">DLA2, S2</span><span style="line-height: 25px; font-family: 宋体; ">——</span><span lang="EN-US" style="line-height: 25px; ">&gt;S1</span><span style="line-height: 25px; font-family: 宋体; ">的叫</span><span lang="EN-US" style="line-height: 25px; ">DLB1, S2</span><span style="line-height: 25px; font-family: 宋体; ">——</span><span lang="EN-US" style="line-height: 25px; ">&gt;S3</span><span style="line-height: 25px; font-family: 宋体; ">的叫</span><span lang="EN-US" style="line-height: 25px; ">DLB2, S3</span><span style="line-height: 25px; font-family: 宋体; ">——</span><span lang="EN-US" style="line-height: 25px; ">&gt;S1</span><span style="line-height: 25px; font-family: 宋体; ">的叫</span><span lang="EN-US" style="line-height: 25px; ">DLC1, S3</span><span style="line-height: 25px; font-family: 宋体; ">——</span><span lang="EN-US" style="line-height: 25px; ">&gt;S2</span><span style="line-height: 25px; font-family: 宋体; ">的叫</span><span lang="EN-US" style="line-height: 25px; ">DLC2,</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span style="line-height: 25px; font-family: 宋体; ">这样</span><span lang="EN-US" style="line-height: 25px; ">SQL</span><span style="line-height: 25px; font-family: 宋体; ">语句分别如下:</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">S1</span><span style="line-height: 25px; font-family: 宋体; ">:</span><span lang="EN-US" style="line-height: 25px; ">select ….from Student,Course@DLA1,S_C@DLA2 where…..;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">S2</span><span style="line-height: 25px; font-family: 宋体; ">:</span><span lang="EN-US" style="line-height: 25px; ">select … from Student@DLB1,Course,S_C@DLB2 where…..;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">S3</span><span style="line-height: 25px; font-family: 宋体; ">:</span><span lang="EN-US" style="line-height: 25px; ">select ….from Student@DLC1,Course@DLC2,S_C where….;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span style="line-height: 25px; font-family: 宋体; ">这就导致一个问题,同样的应用放在三台服务器上,</span><span lang="EN-US" style="line-height: 25px; ">sql</span><span style="line-height: 25px; font-family: 宋体; ">语句是不一样的。</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span style="line-height: 25px; font-family: 宋体; ">下面我们可以建立同义词:</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">S1</span><span style="line-height: 25px; font-family: 宋体; ">:</span><span lang="EN-US" style="line-height: 25px; ">Create public synonym Course for Course@DLA1;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; "><span style="line-height: 25px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Create public synonym S_C for S_C@DLA2;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">S2</span><span style="line-height: 25px; font-family: 宋体; ">:</span><span lang="EN-US" style="line-height: 25px; ">Create public synonym Student for Student@DLB1;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; "><span style="line-height: 25px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Create public synonym S_C for S_C@DLB2;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">S3</span><span style="line-height: 25px; font-family: 宋体; ">:</span><span lang="EN-US" style="line-height: 25px; ">Create public synonym Student for Student @DLC1;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; "><span style="line-height: 25px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>Create public synonym Course for Course@DLC2;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span style="line-height: 25px; font-family: 宋体; ">这样</span><span lang="EN-US" style="line-height: 25px; ">SQL</span><span style="line-height: 25px; font-family: 宋体; ">语句分别如下:</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">S1</span><span style="line-height: 25px; font-family: 宋体; ">:</span><span lang="EN-US" style="line-height: 25px; ">select ….from Student,Course,S_C where…..;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">S2</span><span style="line-height: 25px; font-family: 宋体; ">:</span><span lang="EN-US" style="line-height: 25px; ">select … from Student,Course,S_C where…..;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">S3</span><span style="line-height: 25px; font-family: 宋体; ">:</span><span lang="EN-US" style="line-height: 25px; ">select ….from Studeng,Course,S_C where….;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span style="line-height: 25px; font-family: 宋体; ">可以看到</span><span lang="EN-US" style="line-height: 25px; ">Sql</span><span style="line-height: 25px; font-family: 宋体; ">语句在三台服务器上是一样的。</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">&nbsp;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">&nbsp;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">&nbsp;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">&nbsp;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">&nbsp;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">&nbsp;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">&nbsp;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">&nbsp;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">&nbsp;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">&nbsp;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">&nbsp;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">&nbsp;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">&nbsp;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span lang="EN-US" style="line-height: 25px; ">&nbsp;</span></p><span style="line-height: 52px; font-family: 宋体; ">数据库设计讨论</span><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span style="line-height: 25px; font-family: 宋体; ">数据库设计是指对于一个给定的应用环境,构造最优的数据库模式,建立数据库及其应用系统,使之能够有效地存储数据,满足各种用户的应用需求。</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span style="line-height: 25px; font-family: 宋体; ">对于数据量比较小的小型应用来说,数据库设计非常简单,只需建几张表就可以了,但是当数据量非常大时,就需要考虑以后的应用需求,比如说我们公司,以后的数据量肯定会特别大,这个时候仅仅能够把数据存到数据库中是不行的,因为我们还需要在后台将数据进行显示,这里就涉及到数据库的搜索,以及对搜索出来的数据进行统计。在数据库设计阶段就应该将这些问题考虑进来。</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span style="line-height: 25px; font-family: 宋体; ">对于如何设计才能提高数据库的查询效率,我这里只是简单的介绍几点:</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span lang="EN-US" style="line-height: 25px; ">1&nbsp;</span><span style="line-height: 25px; font-family: 宋体; ">数据库索引,这也是最普通的一种,一般情况下索引可以优化查询,提高查询效率,但是并不是说索引越多越好,还要考虑数据更新问题,当然创建索引应该保证它的有效性。索引的类型有</span><span lang="EN-US" style="line-height: 25px; ">B*_Tree</span><span style="line-height: 25px; font-family: 宋体; ">索引和位图索引。</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span lang="EN-US" style="line-height: 25px; ">2&nbsp;</span><span style="line-height: 25px; font-family: 宋体; ">大表问题,如果一项业务涉及到得数据字段特别多,这时候设计表的原则一般情况下是将经常使用的字段放在一个表中,不经常使用的字段放在另一个表中,表之间用外键关联,这一也会提高数据库的搜索效率。</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span style="line-height: 25px; font-family: 宋体; ">这是因为,如果一个表有</span><span lang="EN-US" style="line-height: 25px; ">20</span><span style="line-height: 25px; font-family: 宋体; ">个字段,我们只需搜索其中的几个字段,如</span><span lang="EN-US" style="line-height: 25px; ">select id,name,age from customer,</span><span style="line-height: 25px; font-family: 宋体; ">在</span><span lang="EN-US" style="line-height: 25px; ">Oracle</span><span style="line-height: 25px; font-family: 宋体; ">内部,它实际上并不是只搜索这几个字段,而是将</span><span lang="EN-US" style="line-height: 25px; ">20</span><span style="line-height: 25px; font-family: 宋体; ">个字段全部搜索出来,然后再进行计算,所以把大表分成小表时,可以在一定程度上提高搜索效率。</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span lang="EN-US" style="line-height: 25px; ">3&nbsp;</span><span style="line-height: 25px; font-family: 宋体; ">分表,当数据量非常大时,仅仅采用索引是不行的,在一个表中如果有上亿条记录,这时候即使有索引查询也会非常慢,因为在一个表中存储上亿条记录是没有任何意义,这时候就应该去采用一些存储策略,因为数据库不会怕表多,怕的是数据过于集中,数据量大时可以采用分表技术,将数据分成</span><span lang="EN-US" style="line-height: 25px; ">10</span><span style="line-height: 25px; font-family: 宋体; ">张表,或者</span><span lang="EN-US" style="line-height: 25px; ">20</span><span style="line-height: 25px; font-family: 宋体; ">张表,然后根据情况到具体的某些表中去查询,当然业务不同采用的分表策略也不同,比如可以按照主键,主索引进行分表,也可以按照时间进行,或者按照地区,当然也可以结合起来进行分表。</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span lang="EN-US" style="line-height: 25px; ">4&nbsp;</span><span style="line-height: 25px; font-family: 宋体; ">表空间,对于不同用途的数据放在不同的表空间。</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span lang="EN-US" style="line-height: 25px; ">5&nbsp;</span><span style="line-height: 25px; font-family: 宋体; ">分区,</span><span lang="EN-US" style="line-height: 25px; ">Oracle</span><span style="line-height: 25px; font-family: 宋体; ">提供了分区技术以支持</span><span lang="EN-US" style="line-height: 25px; ">VLDB(Very Large DataBase)</span><span style="line-height: 25px; font-family: 宋体; ">。分区表通过对分区列的判断,把分区列不同的记录,放到不同的分区中。分区完全对应用透明。</span><span lang="EN-US" style="line-height: 25px; ">Oracle</span><span style="line-height: 25px; font-family: 宋体; ">的分区表可以包括多个分区,每个分区都是一个独立的段(</span><span lang="EN-US" style="line-height: 25px; ">SEGMENT</span><span style="line-height: 25px; font-family: 宋体; ">),可以存放到不同的表空间中。查询时可以通过查询表来访问各个分区中的数据,也可以通过在查询时直接指定分区的方法来进行查询。</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span style="line-height: 25px; font-family: 宋体; ">分区提供以下优点:</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span style="line-height: 25px; font-family: 宋体; ">由于将数据分散到各个分区中,减少了数据损坏的可能性;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span style="line-height: 25px; font-family: 宋体; ">可以对单独的分区进行备份和恢复;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span style="line-height: 25px; font-family: 宋体; ">可以将分区映射到不同的物理磁盘上,来分散</span><span lang="EN-US" style="line-height: 25px; ">IO</span><span style="line-height: 25px; font-family: 宋体; ">;</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span style="line-height: 25px; font-family: 宋体; ">提高可管理性、可用性和性能。</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span lang="EN-US" style="line-height: 25px; ">6 SQL</span><span style="line-height: 25px; font-family: 宋体; ">优化</span></p><p style="line-height: 25px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; "><span lang="EN-US" style="line-height: 25px; ">7&nbsp;</span><span style="line-height: 25px; font-family: 宋体; ">硬件设备,采用大型服务器,高性能的磁盘控制器,多个高速的磁盘,足够的内存等等,也可以提高查询的效率。</span></p></span></div>
页: [1]
查看完整版本: Oracle数据库对象—同义词