exam questions

Exam 70-762 All Questions

View all questions & answers for the 70-762 exam

Exam 70-762 topic 1 question 128 discussion

Actual exam question from Microsoft's 70-762
Question #: 128
Topic #: 1
[All 70-762 Questions]

You are designing a stored procedure for a database named DB1.
The following requirements must be met during the entire execution of the stored procedure:
✑ The stored procedure must only read changes that are persisted to the database. statements within the stored procedure should only show changes to the data that are made by the stored procedure.
✑ SELECT
You need to configure the transaction isolation level for the stored procedure.
Which Transact-SQL statement or statements should you run?

  • A. SET TRANSACTION ISOLATION LEVEL READ UNCOMMITED ALTER DATABASE DB1 SET READ_COMMITED_SNAPSHOT ON
  • B. SET TRANSACTION ISOLATION LEVEL READ COMMITED ALTER DATABASE DB1 SET READ_COMMITED_SNAPSHOT OFF
  • C. SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
  • D. SET TRANSACTION ISOLATION LEVEL READ UNCOMMITED ALTER DATABASE SET READ_COMMITED_SNAPSHOT OFF
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️
READ COMMITTED specifies that statements cannot read data that has been modified but not committed by other transactions. This prevents dirty reads. Data can be changed by other transactions between individual statements within the current transaction, resulting in nonrepeatable reads or phantom data. This option is the SQL Server default.
Incorrect Answers:
A, D: READ UNCOMMITTED specifies that statements can read rows that have been modified by other transactions but not yet committed.
References:
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/snapshot-isolation-in-sql-server

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Zikato
Highly Voted 5 years, 4 months ago
I think C is correct: statements within thestored procedure should only show changes made by the stored procedure - that IMHO means no repeatable reads and no phantom reads.
upvoted 26 times
JohnFan
5 years, 3 months ago
Read Committed focuses on Change, whereas Serializable emphasizing inserting. Under Serializable, SQL Server locks data for a read operation and also uses key-range locks to prevent any other transactions from inserting or modifying the data for the duration of a transaction. This high level of locking reduces concurrency and potentially slows performance due to locking contention.
upvoted 1 times
JohnFan
5 years, 3 months ago
"The stored procedure must only read changes that are persisted to the database. statements within the stored procedure should only show changes to the data that are made by the stored procedure." With Serializable, I think you cannot read changes or show changes, because you just cannot change at the first place..
upvoted 1 times
Nickname17
5 years, 2 months ago
So for C, cross-container transactions are still possible. The only way to prevent cross-container is B.
upvoted 2 times
...
LeonLeon
4 years, 11 months ago
It is important to note that the transaction isolation level does not affect a transaction's ability to see its own changes; transactions can always see any changes they make. For example, a transaction might consist of two UPDATE statements, the first of which raises the pay of all employees by 10 percent and the second of which sets the pay of any employees over some maximum amount to that amount. This succeeds as a single transaction only because the second UPDATE statement can see the results of the first. https://docs.microsoft.com/en-us/sql/odbc/reference/develop-app/transaction-isolation-levels?view=sql-server-ver15
upvoted 5 times
...
...
...
Hoglet
5 years ago
Agree, option C A and D are out because they are both using READ UNCOMMITED, making everything else irrelevent. B and C seem equally good options (neither are making use of READ_COMMITED_SNAPSHOT). Where they differ is the behaviour within a transaction. B will only show changes persisted to the database, but allow changes to be made after the inital read. C will not allow the data to be changed once it's been read. If not within a transaction, they will behave the same way. As the requirement is to "only show changes to the data that are made by the stored procedure", option B could violate this.
upvoted 4 times
...
...
Alex5x
Highly Voted 4 years, 8 months ago
The question in fact sounds like this: The following requirements must be met during the entire execution of the stored procedure: - The stored procedure must only read changes that are persisted to the database. - SELECT statements within the stored procedure should only show changes to the data that are made by the stored procedure. Obviously, READ UNCOMMITED cannot be used here because of the first requirement. So forget about options A and D. READ COMMITTED cannot be used because of the second reqirement. As you know, when READ COMMITTED is used, data can be changed by other transactions between individual statements within the current transaction, resulting in nonrepeatable reads or phantom data. Only SERIALIZABLE can guarantee that both conditions are met. So C is correct.
upvoted 10 times
geekeek1
4 years, 5 months ago
Best explanation
upvoted 1 times
...
...
eggzamtaker
Most Recent 4 years, 5 months ago
The answer is clearly C.
upvoted 1 times
...
lh2607
4 years, 7 months ago
Answer is C. "Statements within the stored procedure should only show changes to the data that are made by the stored procedure." If it was Read Committed then other transactions can still update the data. With Serializable the other transactions are locked out, hence why Serializable is very consistent but not concurrent.
upvoted 2 times
...
414
4 years, 9 months ago
I think A is correct. We are setting the transaction isolation level to read uncommitted but after that, the database isolation level is changed to Read Committed Snapshot. transaction isolation level cannot override Read Committed Snapshot (https://dba.stackexchange.com/questions/229582/is-it-possible-to-override-a-readcommittedsnapshot-isolation-level-with-readcomm) and because of that, transaction will use RCS Isolation level.
upvoted 1 times
Cococo
4 years, 9 months ago
SET READ_COMMITED_SNAPSHOT ON is only for RC, "SQL Server introduced extensions to the SQL-92 isolation levels with the introduction of the SNAPSHOT isolation level and an additional implementation of READ COMMITTED. " https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/snapshot-isolation-in-sql-server
upvoted 2 times
...
...
Nickname17
5 years, 1 month ago
What C does is that it ensures that query returns the same results each time that it is run during the stored procedure.
upvoted 2 times
Luzix
4 years, 7 months ago
Yes, if you want to prevent others tasks insert, update or delete any records yo should use SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
upvoted 1 times
...
...
gtc108
5 years, 2 months ago
The answer is A: SET READ_COMMITED_SNAPSHOT ON because the stored procedure has to read changes it self commits.
upvoted 1 times
Hoglet
5 years ago
But option A also used isolation level of READ UNCOMMITED, so will read all uncommitted changes.
upvoted 2 times
...
lh2607
4 years, 7 months ago
Its not. Its C. Read the requirement about the updating.
upvoted 1 times
...
...
JohnFan
5 years, 3 months ago
SET READ_COMMITTED_SNAPSHOT ON; With this setting enabled, all queries that normally execute using the READ COMMITTED isolation level switch to using the READ_COMMITTED_SNAPSHOT isolation level without requiring you to change the query code. SQL Server creates a snapshot of committed data when each statement starts. Consequently, read operations at different points in a transaction might return different results. During the transaction, SQL Server copies rows modified by other transactions into a collection of pages in tempdb known as the version store. When a row is updated multiple times, a copy of each change is in the version store. This set of row versions is called a version chain.
upvoted 5 times
Nickname17
5 years, 1 month ago
Note that the question states “ The stored procedure must only read changes that are persisted to the database”, which means not for #tempTable. It indicates that it not asking two transactions . For serializable you can still set up snapshot https://link.springer.com/referenceworkentry/10.1007%2F978-1-4614-8265-9_80774
upvoted 1 times
...
Hoglet
5 years ago
The only option where we SET READ_COMMITTED_SNAPSHOT ON; is where the Isolation level is READ UNCOMMITED.
upvoted 2 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...