Consider a database table T containing two columns X and Y each of type…

2021

Consider a database table T containing two columns X and Y each of type integer. After the creation of the table, one record (X=1, Y=1) is inserted in the table. Let MX and MY denote the respective maximum values of X and Y among all records in the table at any point in time. Using MX and MY, new records are inserted in the table 128 times with X and Y values being MX+1, 2*MY+1 respectively. It may be noted that each time after the insertion, values of MX and MY change. What will be the output of the following SQL query after the steps mentioned above are carried out?

SELECT Y FROM T WHERE X=7

  1. A.

    127

  2. B.

    255

  3. C.

    129

  4. D.

    257

  5. E.

    Question not attempted

Attempted by 607 students.

Show answer & explanation

Correct answer: A

Step 1: Start with the initial record (X=1, Y=1). So, MX = 1 and MY = 1. Step 2: Each insertion uses X = MX + 1 and Y = 2 * MY + 1. After each insertion, MX and MY are updated to the new maximum values. Step 3: Track the values after each insertion: Insertion 1: X = 1+1 = 2, Y = 2*1+1 = 3. MX=2, MY=3. Insertion 2: X = 2+1 = 3, Y = 2*3+1 = 7. MX=3, MY=7. Insertion 3: X = 3+1 = 4, Y = 2*7+1 = 15. MX=4, MY=15. Insertion 4: X = 4+1 = 5, Y = 2*15+1 = 31. MX=5, MY=31. Insertion 5: X = 5+1 = 6, Y = 2*31+1 = 63. MX=6, MY=63. Insertion 6: X = 6+1 = 7, Y = 2*63+1 = 127. MX=7, MY=127. Step 4: After 6 insertions, the table contains a record with X=7 and Y=127. Step 5: The SQL query SELECT Y FROM T WHERE X=7 will return Y=127.

Explore the full course: Up Lt Grade Assistant Teacher 2025