Question : Prevent Deadlock in Database Coldfusion

Regarding an ecommerce sight:

I want to make sure that if two or more users each process a transaction at the same time, the database will not deadlock.

Please advise on the best practices for inserting a single row in a table and preventing a deadlock.

Thanks in advance.

Answer : Prevent Deadlock in Database Coldfusion

(no points)

I've only skimmed this thread.  But for the sake of your ecommerce application there's some potentially _dangerous_ and incorrect advice being given here.  This is really a db question, not CF. So I would suggest you ask in a database zone so you can get advice from _experienced_ db experts.  

Cflock is NOT intended as a substitute for proper database locking.  It used to be used for MS Access (only) because Access is a desktop database. It doesn't fully support transactions the way a real db like Oracle, MySQL, etc... do.  Misusing cflock can easily single thread your application. That's very bad for a web site that is supposed to handle concurrency

> I thought cftransaction helps when you have multiple queries to run at the same time.

Correct.  The main purpose is to group multiple statements together so either all of them succeed or all of them fail. The goal being to prevent "partial" modifications.  The typical example given is banking applications.   A transfer involves two steps:  1) withdrawal from one account and 2) deposit into another account.  If only step 1) occurred and then step 2) failed  the data would be corrupt (and customers would be rather upset ). A transaction is designed to ensure that does NOT happen.

> How can it prevent a deadlock occuring from multiple users?

My question would be,  why are you assuming you will have a deadlock ... ? Deadlocks are complicated. They occur because of a "catch 22" type situation.  Again, I would suggest you ask this question of _experienced_ database experts that can provide you with more solid advice based on real life experience, rather than just links.

Good Luck!

Random Solutions  
programming4us programming4us