Skip to content

SA0065A : Check all Triggers for following specified naming convention

Ensure consistent trigger naming convention to avoid confusion and maintenance challenges.

In SQL Server, triggers are special procedures that automatically execute in response to certain events on a table or view. Triggers play a crucial role in maintaining data integrity, managing business logic, and enforcing constraints. However, a common problem arises when triggers are not named consistently or descriptively, leading to confusion and making maintenance more challenging.

For example:

-- Example of a trigger with a vague name
CREATE TRIGGER trg ON SalesTable FOR INSERT AS BEGIN
-- Trigger logic here
END;

The above example is problematic because the trigger name ‘trg’ does not convey any meaningful information about its function or the event it responds to. This can cause confusion during maintenance or when troubleshooting issues.

  • Lack of meaningful trigger names can obscure the purpose and function of the triggers, complicating debugging and documentation efforts.

  • Inconsistent naming can lead to difficulties in managing triggers across multiple databases and servers, where naming conventions become essential for differentiating similar components.

Ensure consistent trigger naming conventions in SQL Server databases to help maintain clarity and avoid confusion and maintenance challenges.

Follow these steps to address the issue:

1.Review the existing trigger names and identify any that do not follow your organization’s naming conventions. Focus on meaningful and descriptive naming that conveys the trigger’s purpose and the event it responds to.

2.Determine the naming convention that best suits your organization’s standards. A good practice is to include the event, table name, and action in the trigger name. For example, trg_SalesTable_Insert .

3.Rename the triggers that do not comply with the established naming convention using SQL Server Management Studio (SSMS) or T-SQL commands. Ensure refactoring is comprehensive to update all references to the changed names.

For example:

-- Rename a trigger with a more descriptive name
ALTER TRIGGER trg_SalesTable_Insert
ON SalesTable
FOR INSERT
AS
BEGIN
-- Trigger logic here
END;

The rule has a ContextOnly scope and is applied only on current server and database schema.

Name Description Default Value
DmlTriggerNamePattern Table triggers name pattern. trig_{trigger_events}{table_name}
DmlTriggerSchemaQualifiedNamePattern DmlTrigger schema qualified name pattern. -
DdlTriggerNamePattern Database and server triggers name pattern. regexp:{triggerevents}[A-Z]A-Za-z1-9]+
InsertEventName Event name which to be used in the {trigger_events} placeholder for the specific event type. i
UpdateEventName Event name which to be used in the {trigger_events} placeholder for the specific event type. u
DeleteEventName Event name which to be used in the {trigger_events} placeholder for the specific event type. d
TriggerEventsListSeparator Separator for the event in the {trigger_events} placeholder.
DdlTriggerEventNames Specifies how the trigger event types are set in the {trigger_events} placeholder. Use first letter of each word (lowercase)

The rule requires Analysis Context. If context is missing, the rule will be skipped during analysis.

8 minutes per issue.

Naming Rules, Code Smells

There is no additional info for this rule.

Analysis Rules