CS FundamentalsModerateTCS NQT · Infosys pattern
A query uses `SELECT ... FOR UPDATE` to explicitly lock the rows it reads within a transaction. What is the main purpose of this, compared to a plain SELECT under READ COMMITTED?
- A. It makes the SELECT run faster
- B. It acquires an exclusive (or update) lock on the selected rows immediately, preventing other transactions from modifying (or in some systems even reading) them until this transaction commits — used to safely read-then-update a row without losing the update to a concurrent transaction
- C. It guarantees the query returns results in a specific sorted order
- D. It disables the use of any index for that query
Correct answer: B. It acquires an exclusive (or update) lock on the selected rows immediately, preventing other transactions from modifying (or in some systems even reading) them until this transaction commits — used to safely read-then-update a row without losing the update to a concurrent transaction
SELECT ... FOR UPDATE is the standard way to avoid the lost-update anomaly under weaker isolation levels: by locking the rows as soon as they are read, no other transaction can sneak in and modify them before this transaction performs its own update based on what it read, closing the window a plain SELECT would otherwise leave open.
More DBMS and SQL questions
- A long-running read-only transaction under snapshot isolation sees a consistent view of the database as of its start time, even while…
- A relation R(A, B, C) has the single functional dependency A → B (C is independent, with no FD at all involving it, and no candidate key…
- A table's clustered index key is UUID-based (a random 128-bit value) rather than a sequential integer. What problem does this commonly…
- After a crash, the analysis phase of ARIES recovery scans the log forward from the last checkpoint to rebuild the transaction table…
- A relation Enrollment(studentid, courseid, semester, grade) has candidate key (studentid, courseid, semester). A functional dependency…
- A poorly designed table stores repeating groups as separate columns: Student(sid, sname, course1, course2, course3). What specific 1NF…