Mysql – How are the following situations handled in MySQL

MySQL

Q1. What happens if two rows are inserted simultaneously in a table where a column is marked unique and both rows have same value for that column.

Q2. What happens if a row is being updated and at the same time another query tries to delete it.

Best Answer

UPDATEs and DELETEs will at very least apply a row level lock that prevents other transactions from affecting that row until the locking transaction is complete. If the LOCK takes 'too' long to resolve the transaction it can result in a TIMEOUT or a DEADLOCK scenario. Transactions are applied in a synchronous manner based upon when the command reaches the database.