linux truncate 命令,truncate 命令使用

linux truncate 命令,truncate 命令使用今天使用truncate清空表时报错了:SQL>truncatetableref_set;truncatetableref_setORA-02266:表中的唯一/主键被启用的外键引用通过dba_constraints查看,该表的主键被其他表所引用,因此无法truncate。即使从表中的数据被清空或者从来没有过数据,也无法直接对被引用的表执行truncate操作。解决方法:alte…

今天使用truncate清空表时报错了:

SQL> truncate table ref_set;

truncate table ref_set

ORA-02266: 表中的唯一/主键被启用的外键引用

通过dba_constraints查看,该表的主键被其他表所引用,因此无法truncate。即使从表中的数据被清空或者从来没有过数据,也无法直接对被引用的表执行truncate操作。

解决方法:alter table tab_name disable constraint constraint_name;

说明:以前曾经听过关于truncate的限制,但实际工作中由于用的比较少,渐渐忘了。

除了存在外键约束而无法执行truncate外,还应该注意:truncate是ddl操作,如果在执行truncate过程中由其他用户的dml操作没有提交,truncate会触发其提交操作。因此在并发比较高的系统中慎重使用truncate命令。

根据表名查询有哪些外键调用了该表中的列:

select a.table_name “被引用表”,a.constraint_name “约束名”,

b.constraint_name “外键名”,b.table_name “引用表” from dba_constraints a,dba_constraints b

where a.constraint_type=’P’ and a.owner=:COLUMN_NAME

and a.constraint_name=b.r_constraint_name;

以下直接产生禁用约束的语句:

select ‘alter table ‘||b.table_name||’disable constraint ‘||b.constraint_name

from dba_constraints a,dba_constraints b

where a.constraint_type=’P’ and a.owner=:COLUMN_NAME

and a.constraint_name=b.r_constraint_name and a.table_name=:table_name;

今天的文章linux truncate 命令,truncate 命令使用分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/11490.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注