1.

How many models of Locks being supported in the SQL server?

Answer»

An optimistic lock is the WIDELY used strategy UTILIZED in n tier applications were while reading data from the database we check versioning of data before writing it back to the database. The versioning is done on a date, timestamps or checksum/hashes. This approach is used to prevent DIRTY read scenario where we take a decision based on data which is not yet committed in the database. 

The optimistic approach will ensure that in case dirty read is identified based on versioning we will start from fresh. This strategy is popular where system deals with a high volume of data and even in the case of n tier applications where we are not always connected to a database with single connections. It is a pool of connection from which we connect to the database with any connection which is free and available at that TIME. We can not apply lock in such cases. This strategy is applied in most of the banking operations.

Pessimistic is just opposite of Optimistic lock as it takes an exclusive lock on resources till the time we finish with our operations. It keeps data integrity high but performance will be always slower in this case. We NEED to connect to a database with an active connection (which is the case in two-tier application).



Discussion

No Comment Found