Minor

Triggers should not PRINT, SELECT, or FETCH

Description

    The "Triggers should not PRINT, SELECT, or FETCH" rule states that triggers should not use the PRINT, SELECT, or FETCH commands when executing code. These commands are used to display data from a database, and should not be used in triggers because they can cause unexpected results. Instead, triggers should use the INSERT, UPDATE, and DELETE commands to modify data in a database. This rule ensures that triggers are used properly and do not cause unexpected results.

Key Benefits

  • No Data Leakage: Triggers should not PRINT, SELECT, or FETCH as this can lead to data leakage.
  • Increased Security: Triggers should not PRINT, SELECT, or FETCH as this can help provide an extra layer of security.
  • Better Performance: Triggers should not PRINT, SELECT, or FETCH as this can improve performance by reducing the amount of data being processed.

 

Non-compliant Code Example

CREATE TRIGGER [DATA].Employee_Count
ON [DATA].EMPLOYEE
AFTER DELETE
AS
BEGIN
    DECLARE @n int
    SELECT @n = COUNT(*) FROM [DATA].EMPLOYEE    --Non compliant code (Trigger is having Select clause)
    PRINT ' There are now ' + CAST(@n as nvarchar(10)) + ' employees.'  --Non compliant code (Trigger is having Print clause)
END
Visual Expert 2023
 VETSQLRULE47