Programming with Database is very challenging. It is all about you designed and normalized the database really correctly without missing any important indexing and writing the most optimized queries. In addition to that database programmer should be aware of whether the order of the queries in an execution flow will make a deadlock specially in very complex systems.
There are many guidelines that you can follow specially on avoiding (probably minimizing) deadlocks. Specially the guide "Reducing SQL Server Deadlocks" provides a checklist to reduce deadlocks in a database program.