DF206: The PRINT statement is used in the trigger.

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

Category

PERFORMANCE

Message

The PRINT statement is used in the trigger.

Description

Triggers should not return messages to the client.

Aadditional information

Triggers should not return messages to the client to maintain transaction integrity and performance. Triggers are designed to enforce business rules and maintain data consistency within the database. Returning messages can disrupt this process, create unnecessary overhead, and lead to unexpected client behavior. Instead, errors and business rules should be enforced by causing transactions to fail, allowing the application layer to handle messaging and user interactions. This separation of concerns ensures a clear distinction between data management and client communication, which enhances security and efficiency.

Noncompliant code example

CREATE OR ALTER TRIGGER [Labour].[trg_WorkOut]
ON [Labour].[WorkOut]
AFTER INSERT, UPDATE
AS BEGIN
    PRINT 'In Trigger';
    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
 
    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?