One of the classical reason we have a database deadlock is when two transactions are inserting \updating tables in a different order.
e.g. Transaction A inserts in Table A then Table B
and Transaction B inserts in Table B followed by A
Such a scenario is always at risk of a database deadlock (assuming you are not using serializable isolation level)
My question is
A) What kind of patterns do you follow in your design to make sure that all transactions are inserting\updating in the same order. A book I was reading- had a suggestion that you can sort the statements by the name of the table. Have you done something like this or different - which would enforce that all inserts\updates are in the same order ?
B) What about deleting records ? Delete needs to start from child tables and updates\inserts need to start from parent tables How do you ensure that this would not run into a deadlock ?