Skip to content

SA0241 : Check transaction and savepoint names for following specified naming convention

Consistent and meaningful naming of transactions and savepoints enhances readability and maintainability, reducing confusion and errors in complex or collaborative environments.

Using consistent and meaningful names for transactions and savepoints improves code readability and maintainability. When names deviate from a standard pattern, it can lead to confusion and errors, especially in complex databases or collaborative projects.

For example:

-- Example of a transaction with a non-standard name
BEGIN TRAN myTrans;
SAVE TRAN s1;
COMMIT TRAN myTrans;

In this example, the transaction name myTrans and savepoint name s1 do not follow any specific naming convention, which can make it harder to understand the purpose and scope of the transaction in larger scripts.

  • Lack of standard naming can complicate debugging and maintenance, as developers may struggle to associate transactions with their actions.

  • Non-descriptive names reduce code clarity, impacting code reviews and increasing the likelihood of errors in multi-developer environments.

Ensure transaction and savepoint names adhere to specified naming conventions to improve code readability and maintainability.

Follow these steps to address the issue:

1.Review the existing transaction and savepoint names within your T-SQL scripts. Identify names that do not conform to your project’s established naming conventions.

2.Update non-standard names to follow the specified patterns outlined in the rule parameters. Ensure that names are descriptive and indicative of their purpose.

3.Test the updated T-SQL scripts to confirm that all transaction and savepoint names are correctly applied and that the refactoring has not introduced any errors.

For example:

-- Example of corrected transaction names with standard conventions
BEGIN TRAN Transaction_OrderProcess;
SAVE TRAN Savepoint_BeforePayment;
COMMIT TRAN Transaction_OrderProcess;

The rule has a Batch scope and is applied only on the SQL script.

Name Description Default Value
TransactionNamePattern Transaction name pattern. regexp:[A-Z][A-Za-z_]+
SavepointNamePattern Savepoint name pattern. regexp:[A-Z][A-Za-z_]+
DistributedTransactionNamePattern Distributed transaction name pattern. regexp:[A-Z][A-Za-z_]+

The rule does not need Analysis Context or SQL Connection.

8 minutes per issue.

Naming Rules, Code Smells

There is no additional info for this rule.

BEGIN DISTRIBUTED TRAN TRAN1
COMMIT TRAN TRAN1
BEGIN TRANSACTION TRAN_1
SAVE TRANSACTION TRAN_1_SAVEPOINT
ROLLBACK TRAN TRAN_1
DECLARE @TranName VARCHAR(20);
SELECT @TranName = 'TRAN_3a';
SET @TranName = 'TRAN_3b';
BEGIN TRANSACTION @TranName;
COMMIT TRANSACTION @TranName;
  Message Line Column
1 SA0241 : The distributed transaction name [TRAN1] does not match the naming convention. The expected key name is [[A-Z][A-Za-z_]+]. 1 24
2 SA0241 : The transaction name [TRAN_1] does not match the naming convention. The expected key name is [[A-Z][A-Za-z_]+]. 4 18
3 SA0241 : The savepoint name [TRAN_1_SAVEPOINT] does not match the naming convention. The expected key name is [[A-Z][A-Za-z_]+]. 5 17
4 SA0241 : The transaction name [TRAN_3b] does not match the naming convention. The expected key name is [[A-Z][A-Za-z_]+]. 11 18

Analysis Rules