if we are using the transaction no lock in stored procedure then it will also applicable in functions used inside the procedure or not ?
Loading
if we are using the transaction no lock in stored procedure then it will also applicable in functions used inside the procedure or not ?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Nitin SontakkeRank #264 · 9.6K reputationPosted Jan 5, 2023, 11:14 AM EST
It seems you mean to say HINT (no lock).
If that is what you mean, then the answer is no.
Brahma Prakash ShuklaRank #633 · 3.8K reputationPosted Jan 6, 2023, 2:14 AM EST
So, How we use no lock in whole function used inside the stored procedure and stored procedure contains no lock ?
Note:- we don't need to use no lock in queries used in the function.
Nitin SontakkeRank #264 · 9.6K reputationPosted Jan 6, 2023, 3:42 AM EST
The simplest answer is, you cannot.
Furthermore, the SQL Server community largely discourage this practice altogether.
Anandu G NathRank #681 · 3.5K reputationPosted Dec 20, 2023, 12:33 AM EST
In SQL Server, the behavior of transactions with respect to locking extends to functions called within a stored procedure, depending on how these functions are implemented and their transaction handling.
When a stored procedure is executed within a transaction context with the
NOLOCKhint (or other isolation levels likeREAD UNCOMMITTED), the behavior inside the stored procedure, including the functions it calls, will also adopt the specified isolation level.CREATE PROCEDURE UpdateEmployeeSalary @employeeID INT, @newSalary DECIMAL(10, 2) AS BEGIN BEGIN TRANSACTION; -- Update employee salary in the Employee table UPDATE Employee SET Salary = @newSalary WHERE ID = @employeeID; -- Call the function to get employee details SELECT * FROM dbo.GetEmployeeDetails() WITH (NOLOCK); -- Commit or rollback the transaction based on business logic -- COMMIT TRANSACTION; -- ROLLBACK TRANSACTION; END;