The topic describes the DF068 T-SQL code analysis rule.
BEST PRACTICE
The WAITFOR statement with DELAY
or TIME
is used inside a stored procedure, a function, or a trigger.
It is not recommended to use the WAITFOR DELAY
/TIME
statement in stored procedures, functions, and triggers. These statements introduce intentional delays, which are uncommon and generally unnecessary in most database operations.
Avoid using WAITFOR DELAY
or WAITFOR TIME
:
WAITFOR
holds the session and server resources during the delay, reducing system throughput and potentially blocking other processes.WAITFOR
delays the transaction, potentially affecting the user experience and application logic.CREATE OR ALTER PROCEDURE dbo.DemoProcedure
@Id INT
AS
BEGIN
SET NOCOUNT ON;
SELECT p.FirstName, p.LastName
FROM dbo.Personnel p
WHERE p.Id = @Id;
WAITFOR DELAY '00:00:10';
END
GO
CREATE OR ALTER PROCEDURE dbo.DemoProcedure
@Id INT
AS
BEGIN
SET NOCOUNT ON;
SELECT p.FirstName, p.LastName
FROM dbo.Personnel p
WHERE p.Id = @Id;
END
GO