The topic describes the DF206 T-SQL code analysis rule.
PERFORMANCE
The PRINT statement is used in the trigger.
Triggers should not return messages to the client.
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.
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
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