Reputation: 1409
I have just had to do a SQL exam and I really struggled with 2 questions around transactions, it has been submitted, so this is just for my sanity... What are the answers to these?
Sorry if this shouldn't be here, or if these should be 2 separate questions.
1.
Employee X has a salary of 40,000
a. User A begins a transaction and updates employee X's salary to salary * 1.1
b. User B begins a transaction and updates employee X's salary to salary * 1.25
c. User A rolls back their transaction
d. User B commits their transaction
What is Employee X's salary? (I went with 50,000, there was no mention of transaction isolation level)
2. A script is built up as follows -
a. Transaction start
b. Insert record into table 1
c. Create savepoint
d. Insert record into table 2
e. Rollback to the save point created after the insert into table 1
f. Insert a record into table 3
g. Commit the transaction
Which tables were records inserted into? (I went with table 1 only)
Upvotes: 2
Views: 154
Reputation: 69494
For your question 1 assuming we have default transaction isolation level i.e Read Committed . your answer is right.
Question 1
- User one Begin a transaction and does not commit it
- User two tries to update the same record but his Update will be blocked until user one rolls back his transaction, But once he rolls back his transaction it will be updated to
Salary * 1.25
which is 50000.
Question 2
- Record inserted in table one with a savepoint means if this transaction is rolled back it will not be rolled back all but to the last saved point.
- Insert into table 2 and then rolled back , which will rollback the insert into table 2 but not the insert in table 1 which is protected by the savepoint.
- Insert into table 3 and commmit. Which will save inserts made into table 1 and 3 to the disk.
Upvotes: 6
Reputation: 449
Sorry i didn't get your 1st question.
For Question 2 , Data will be inserted in table1 and table3.
Upvotes: 0