Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1693643
  • 博文数量: 136
  • 博客积分: 10021
  • 博客等级: 上将
  • 技术积分: 3261
  • 用 户 组: 普通用户
  • 注册时间: 2007-01-22 11:26
文章分类

全部博文(136)

文章存档

2010年(1)

2009年(26)

2008年(109)

我的朋友

分类: Oracle

2009-05-27 15:10:12

今天倒腾一些数据,碰到一个被外键关联的表,无法truncate。后来将依赖的表中数据清空后,还是无法truncate,当时很奇怪,后来发现delete是可行的。估计truncate时根本不检查数据间的依赖关系,直接就不让操作,这样比较省事。
 
下面是个小测试:
 
SQL> create table yct1(id number not null, name varchar2(20));
 
Table created
 
SQL> alter table yct1 add constraint pk_yct1 primary key (id); 
 
Table altered
 
SQL> create table yct2 (id number);
 
Table created
 
SQL> alter table yct2 add constraint fk_yct2 foreign key (id) references yct1(id);
 
Table altered
 
SQL> truncate table yct1;
 
truncate table yct1
 
ORA-02266: unique/primary keys in table referenced by enabled foreign keys
 
SQL> delete yct1;
 
0 rows deleted
阅读(5293) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~