What is a LOCK in SQL Server 2008 If you dont use a lock you
What is a LOCK in SQL Server 2008? If you don’t use a lock, you run into these four common problems - define each one:
 
 Lost UpdateDirty
 ReadNon-Repeatable
 ReadPhantom Reads
Solution
Locks are acquired by different transactions on the dependent resources like rows or tables.
 Once a transaction acquires a lock on the resource , it blocks other transactions from modifying that resource. After transaction has no longer dependency on the resource, it releases the lock from that resource.
4 common problems if we don\'t use a lock :
1) Lost Update : Let say Transaction A reads a record and fetches the value into a variable and parallely Transaction B updates this record. Later when Transaction A updates the record as per the value of that variable. Then, update done by Transaction B is a \'Lost Update\'.
2) Dirty Read : Let say Transaction A changes the data but it is still uncommitted and the data is now accessed by Transaction B. This scenario is considered as \"Dirty Read\".
3) Non Repeatable Read :This scenario occurs when a particular data is been accessed by a transaction for more than once and in between these accesses , that particular data is modified or deleted by another transaction. This problem is termed as Non Repeatable Read.
4) Phantom Read : This scenario occurs when a transaction (Transaction A) executes 2 queries, against the same table and use the same ‘WHERE’ clause, but the query executed last returns more rows than the query executed first.This problem is termed as Phantom Read.

