user3601310
user3601310

Reputation: 873

Can two users connected to a DB and update the same row of a table simultaneously in SQL server?

Can two users connected to a DB and update the same row of a table simultaneously in SQL server?

For example, user A and user B are logged in to a same DB simultaneously and begin new transactions and then update a weekly rent simultaneously.

The original weekly rent is $300/pw.

User A: Update RENT Set WeeklyRent = WeeklyRent* 1.1 where Address ='121 Green'

User B: Update RENT Set WeeklyRent = WeeklyRent* 1.2 where Address ='121 Green'

Then User A issues a Commit statement. Then User B issues a Commit statement.

What will be the final rent price? Will this be $330 or $360 or $300? I've researched it and it seems like the data won't change because of 'deadlock'. Please correct me if I'm wrong. Thanks in advance~

Upvotes: 1

Views: 2270

Answers (1)

Russell Bevan
Russell Bevan

Reputation: 334

SQL Server will lock the table/row/page to ensure that you will be able to do the update. However we are talking milliseconds in most cases so it is almost impossible for them to be "simultaneously" updating the same record. Just be sure to always use a transaction and limit connection times because the record will be locked until the transaction ends.

Upvotes: 2

Related Questions