Oracle 11g 新特性--只读表

本文介绍在Oracle11g中如何直接对表设置只读或读写状态,并通过实测展示只读表上允许的操作类型。验证了设置为只读的表可以创建和删除索引,但不允许进行插入、删除、截断或修改表结构。

在oracle 11G之前,无法将单个表设为read only,只能对表空间进行read only操作,11G在这方面做了增强。

在Oracle 11g中,我们可以直接对表的读写权限进行设置:

        ALTER TABLE table_name READ ONLY;

        ALTER TABLE table_name READ WRITE;

 

下面做一个测试:

建立一个表,将其设置为read only

SQL> conn l5m/l5m
Connected.
SQL> create table test_ro as select * from dba_users;

Table created.

SQL> alter table test_ro read only;

Table altered.

下面做一些dml及ddl操作

SQL> select table_name,status,read_only from dba_tables where table_name='TEST_RO';

TABLE_NAME                     STATUS   REA
------------------------------ -------- ---
TEST_RO                        VALID    YES

SQL> insert into test_ro select * from dba_users;
insert into test_ro select * from dba_users
            *
ERROR at line 1:
ORA-12081: update operation not allowed on table "L5M"."TEST_RO"


SQL> delete from test_ro;
delete from test_ro
            *
ERROR at line 1:
ORA-12081: update operation not allowed on table "L5M"."TEST_RO"


SQL> truncate table test_ro;
truncate table test_ro
               *
ERROR at line 1:
ORA-12081: update operation not allowed on table "L5M"."TEST_RO"


SQL> alter table test_ro add col1 varchar2(100);
alter table test_ro add col1 varchar2(100)
*
ERROR at line 1:
ORA-12081: update operation not allowed on table "L5M"."TEST_RO"

发现dml操作是不允许的,truncatec以及对表结构的更改也不允许。

那哪些操作是允许的?

SQL> create index i_test_ro on test_ro(username);

Index created.

SQL> drop index i_test_ro;

Index dropped.

SQL> drop table test_ro;

Table dropped.

对表增加和删除索引是允许的,甚至可以将read only的表删除也是允许的,因为drop操作是对其数据字典进行操作,和表本身不相关的。所以drop的权限不要随便赋予给普通用户!

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值