DF207: Data-returning SELECT statement is used within the trigger.

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

Category

PERFORMANCE

Message

Data-returning SELECT statement is used within the trigger.

Description

Triggers should not return data to the client, as this can lead to unexpected consequences.

Additional information

It is important to note that using a data-returning SELECT statement within a trigger can have performance implications. Each time the trigger fires, the SELECT statement executes, potentially impacting the overall performance of the database, especially if the SELECT statement retrieves a large amount of data or is executed frequently. Additionally, data-modifying triggers can be affected by the use of data-returning SELECT statements, potentially leading to unexpected behavior or performance issues.

Noncompliant code example

CREATE OR ALTER trigger [labour].[trg_workout]
ON [labour].[workout]
AFTER INSERT, UPDATE
AS
BEGIN
  SET NOCOUNT ON
  SELECT id FROM dbo.demotable
  IF EXISTS(SELECT * FROM inserted WHERE Time < 0) ROLLBACK;
END;
GO

Compliant solution

CREATE OR ALTER trigger [labour].[trg_workout]
ON [labour].[workout]
AFTER INSERT, UPDATE
AS
BEGIN
    SET NOCOUNT ON
 
    IF EXISTS(SELECT * FROM inserted WHERE Time < 0) ROLLBACK;
END;
GO

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All Features

All features

Get acquainted with the rich features and capabilities of the Studio in less than 5 minutes.
Request a demo

Request a demo

If you consider employing the Studio for your business, request a demo to see it in action.
Ready to start using dbForge Studio for SQL Server?