Last active
February 18, 2025 14:41
-
-
Save ritacse/b35941df80c620a76dd00b4844b4897f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET NOCOUNT ON; | |
--It's often used at the beginning of stored procedures and triggers. | |
--Benefits of SET NOCOUNT ON | |
--1.Reduces network traffic: | |
--2.Reduces processing | |
--Example: | |
ALTER PROCEDURE [dbo].[CheckUserMenuPermission] | |
@UserId INT, | |
@ControllerName NVARCHAR(100), | |
@ActionResult NVARCHAR(100) | |
AS | |
BEGIN | |
SET NOCOUNT ON; --// ** here it is | |
SELECT * FROM Menu_Permission_T MP INNER JOIN Menu_T M ON MP.MenuID=M.ID | |
where MP.UserID= @UserId and URL = '/'+@ControllerName+'/'+ @ActionResult | |
END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Essentially, "NOCOUNT" controls message display, | |
-- while "NOLOCK" affects data consistency by bypassing locking mechanisms. | |
SELECT * FROM Menu_Permission_T MP WITH (NOLOCK) | |
Example Scenarios: | |
----------------- | |
Use "SET NOCOUNT": | |
When executing a series of updates within a stored procedure where the actual number of rows modified is not critical to the application logic. | |
Use "NOLOCK": | |
When running a read-only query against a large table that is frequently updated, and you can tolerate potentially reading uncommitted changes for faster result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment