1、锁表发生在insert、update、delete中
2、锁表的原理是:数据库使用独占式封锁机制,当执行上面的语句时,对表进行锁住,直到发生commit提交或者rollback回滚退出数据库用户。
3、锁表的原因:
1)A程序执行了对tableA的insert,并还未commit时,B程序也对tableA进行insert,则此时会发生资源正忙的异常,就是锁表。
2)锁表常发生并发而不是并行(并行时,一个线程操作数据库时,另一个线程是不能操作数据库的,cpu和i/o分配原则)
4、减少锁表的概率
1)减少insert、update、delete语句执行到commit之间的时间。将批量执行改为单个执行、优化sql自身的非执行速度。
2)如果异常,对事物进行回滚。
转自: