最近阅读oracle官方文档关于锁机制中有一下一段话
Locks and Unindexed Foreign KeysWhen both of the following conditions are true, the database acquires a full table lock on the child table: No index exists on the foreign key column of the child table. A session modifies a primary key in the parent table (for example, deletes a row or modifies primary key attributes) or merges rows into the parent table. Inserts into the parent table do not acquire table locks on the child table.
按照翻译理解,当子表的外键没有创建索引并且修改主表的主键(删除一行,或者修改主键属性),或者merge行到主表中都会引起子表锁定 于是我就自己做了一个试验, 创建了 p(id nubmer primary key,pname varchar2(20))(主表) c(cid number reference to p(id),cname varchar2(20))(子表) 并分别按照正常规则插入部分数据
试验开始: 我想通过修改主表的主键来达到锁定字表的目的 当我修改主表的时候得到的违法外键约束提示 SQL> update p set id=20 where id=2;update p set id=20 where id=2*ERROR at line 1:ORA-02292: integrity constraint (HR.FK_CID) violated - child record found出现以上结果也是可以理解的
但是疑问就是官方文档中出现的情况到底时在什么情况下出现的,希望各位高手帮忙解答
|