Complete the code to start a transaction in SQL.
BEGIN [1];To start a transaction in SQL, you use BEGIN TRANSACTION.
Complete the code to lock a table for writing in SQL.
LOCK TABLE [1] IN EXCLUSIVE MODE;The LOCK TABLE statement locks a specific table, here the table name is needed.
Fix the error in the SQL code to prevent deadlock by setting the transaction isolation level.
SET TRANSACTION ISOLATION LEVEL [1];Using SERIALIZABLE isolation level helps prevent deadlocks by ensuring transactions are fully isolated.
Fill both blanks to create a query that detects blocking sessions causing deadlocks.
SELECT blocking_session_id, [1] FROM sys.dm_exec_requests WHERE [2] > 0;
The query selects the blocking session and the session being blocked to identify deadlocks.
Fill all three blanks to write a query that kills a blocking session to resolve deadlock.
DECLARE @session_id INT = ([1] TOP 1 blocking_session_id FROM sys.dm_exec_requests WHERE blocking_session_id > 0); IF EXISTS (SELECT 1 FROM sys.dm_exec_sessions WHERE session_id = @session_id) BEGIN [2] [3] @session_id; END
The query assigns a session id using a subquery to find a blocking session, checks if it exists, then executes the KILL command to end the blocking session.