General Guidelines

There is a golden rule relating to locking and performance in database transactions. Any records you lock should remain locked for the minimum possible period of time to reduce database contention caused by other users seeking the same records. This means that operations that take out locks should be called as late as possible in your transactions. For example, if you read several records to validate a transaction, followed by updates to several more records, always perform the validations first followed by the updates. Try to defer update operations (or reads with locks) until as late as possible: don't scan a million-record table after taking out a record lock that ought to be short-lived.