in Databases recategorized by
7,915 views
41 votes
41 votes

A company maintains records of sales made by its salespersons and pays them commission based on each individual's total sales made in a year. This data is maintained in a table with following schema:

salesinfo = (salespersonid, totalsales, commission)

In a certain year, due to better business results, the company decides to further reward its salespersons by enhancing the commission paid to them as per the following formula:

If commission $\leq 50000,$ enhance it by $2\%$
If $50000 <$ commission $\leq 100000,$ enhance it by $4\%$
If commission $> 100000,$ enhance it by $6\%$

The IT staff has written three different SQL scripts to calculate enhancement for each slab, each of these scripts is to run as a separate transaction as follows:

 T1

 
Update salesinfo
Set commission = commission * 1.02
Where commission < = 50000;
 T2

 
Update salesinfo
Set commission = commission * 1.04
Where commission > 50000 and commission is < = 100000;
 T3

 
Update salesinfo
Set commission = commission * 1.06
Where commission > 100000;

Which of the following options of running these transactions will update the commission of all salespersons correctly

  1. Execute T1 followed by T2 followed by T3
  2. Execute T2, followed by T3; T1 running concurrently throughout
  3. Execute T3 followed by T2; T1 running concurrently throughout
  4. Execute T3 followed by T2 followed by T1
in Databases recategorized by
7.9k views

1 comment

Nice solution👍🏻
0
0

1 Answer

112 votes
112 votes
Best answer

Correct Answer $: D$
 

$T3$ followed by $T2$ followed by $T1$ will be correct execution sequence:

other cases some people will get two times increment

eg. if we have $T1$ followed by $T2$

if initial commision is $49500$

then he is belonging to $< 50000$

hence, $49500*1.02 = 50490$

now, he is eligible in second category

then, $50490$*$1.04 = 52509.6$

so, he wil get increment two times. but he is eligible for only one slab of commision.

edited by

4 Comments

wow mazaa aa gya
1
1
Nice answer
0
0
if the query is executed concurrently it could be possible that person with sale 49500 gets updated first and then it would again get updated by t2 query as in concurrent execution parallel execution is there
0
0
Answer:

Related questions