Tham khảo tài liệu 'databases demystified- p7', công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Databases Demystified 4. Finally user B applies his update subtracting the 100 payment from the balance due he retrieved from the database 200 resulting in a new balance due of 100. He is unaware of the update made by user A and thus sets the balance due incorrectly to 100. The balance due for this customer should be 200 but the update made by user A has been overwritten by the update made by user B. The company is out 100 that either will be lost revenue or will take significant staff time to uncover and correct. As you can see allowing concurrent updates to the database without some sort of control can cause updates to be lost. Most database vendors implement a locking strategy to prevent concurrent updates to the exact same data. Locking Mechanisms A lock is a control placed in the database to reserve data so that only one database session may update it. When data is locked no other database session can update the data until the lock is released which is usually done with a COMMIT or ROLLBACK SQL statement. Any other session that attempts to update locked data will be placed in a lock wait state and the session will stall until the lock is released. Some database products such as IBM s DB2 will time out a session that waits too long and return an error instead of completing the requested update. Others such as Oracle will leave a session in a lock wait state for an indefinite period of time. By now it should be no surprise that there is significant variation in how locks are handled by different vendors database products. A general overview is presented here with the recommendation that you consult your database vendor s documentation for details on how locks are supported. Locks may be placed at various levels often called lock granularity and some database products including Sybase Microsoft SQL Server and IBM s DB2 support multiple levels with automatic lock escalation which raises locks to higher levels as a database session places more and more locks on the