Oracle设置表只读-alter table xxx read only

本文详细介绍了从Oracle 11g开始,如何使用SQL命令设置表为只读状态,包括只读设置后的限制操作如插入、更新、删除和截断,以及对表进行与索引相关操作的特殊性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

11g以前,当需要设置一个表只读时,我们通过赋予某些用户select权限。但对于表的owner来说,还是可以读写的。
 

从Oracle 11g开始,我们可以通过一下命令设置表只读或可读可写:
alter table tab1 read only;
alter table tab1 read write;

 

SQL> create table t1 (t number);

Table created

--设置表为只读
SQL> alter table t1 read only;

Table altered

 

--DML操作,insert/update/delete都不允许
SQL> insert into t1 values (1);

insert into t1 values (1)

ORA-12081: update operation not allowed on table "TOUGH"."T1"

 

SQL> update t1 set t=0;

update t1 set t=0

ORA-12081: update operation not allowed on table "TOUGH"."T1"

 

SQL> delete from t1;

delete from t1

ORA-12081: update operation not allowed on table "TOUGH"."T1"

 

--DDL操作,truncate不允许
SQL> truncate table t1;

truncate table t1

ORA-12081: update operation not allowed on table "TOUGH"."T1"

 

SQL> alter table t1 add (a number);

alter table t1 add (a number)

ORA-12081: update operation not allowed on table "TOUGH"."T1"


--虽然表设置成了只读,但此处对表进行与索引相关操作,因为索引修改的是数据字典,和表不相关,所以可以进行
SQL> create index t1_indx on t1(t);

Index created

 


 

 

转载于:https://www.cnblogs.com/toughhou/p/3778791.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值