I have a general question on how to avoid deadlocks when reading from table which is being updated by another transactions.
In short, I have a loader software installed on the server, it runs multiple time a day as scheduled. It will download new data files from FTP and load them into the database.
In the meanwhile, I also have the need to read from those tables whenever a user calls. I have seen some times, it throws out errors like this, if the table I was trying to read from, happen to be locked as the loader is writing to the same table.
Transaction (Process ID xx) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction'
I was wondering if there is a optimal way to let the user still be able to read even if it is being locked. Some suggests set the isolation level to read uncommited (dirty read), but my concern is dirty read is very incosistant and it might return duplicates.
Ideally, I want to read committed data only but still avoid deadlocks. Any better idea on this?