DF068: The WAITFOR statement with DELAY or TIME is used inside a stored procedure, a function, or a trigger.

Last modified: June 12, 2025

The topic describes the DF068 T-SQL code analysis rule.

Category

BEST PRACTICE

Message

The WAITFOR statement with DELAY or TIME is used inside a stored procedure, a function, or a trigger.

Description

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.

Additional information

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.
  • In high-traffic environments, introducing delays can cause lock contention and increase response times.
  • When used in triggers, WAITFOR delays the transaction, potentially affecting the user experience and application logic.

Noncompliant code example

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

Compliant solution

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