APX1109 – QUOTED_IDENTIFIERS or ANSI_NULLS in a programmability object
Description:
This rule evaluates the T-SQL script for using QUOTED_IDENTIFIERS or ANSI_NULLS options inside programmability objects.
Using QUOTED_IDENTIFIERS or ANSI_NULLS options inside programmability objects will be ignored.
For more information visit
Example script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
CREATE PROCEDURE proc_QIorANSIFirstFailedEx AS BEGIN SET QUOTED_IDENTIFIER OFF; SET ANSI_NULLS OFF; SELECT * FROM FirstTable; END; GO CREATE PROCEDURE proc_QIorANSISecondFailedEx AS BEGIN SET ANSI_NULLS OFF; SELECT * FROM SecondTable; END; GO CREATE PROCEDURE proc_QIorANSIThirdFailedEx AS BEGIN SET QUOTED_IDENTIFIER OFF; SELECT * FROM ThirdTable; END; GO CREATE PROCEDURE proc_QIorANSIFirstGoodEx AS BEGIN SELECT * FROM FourthTable; END; GO CREATE PROCEDURE QIorANSISecondGoodEx AS BEGIN SELECT * FROM FifthTable; END; GO |
Message:
Consider removing QUOTED_IDENTIFIER or ANSI_NULLS type identifier as they are ignored in this context
APX1118 – Unassigned variable
Description:
This rule evaluates the T-SQL script for having variables that have been declared but never assigned or used, where it should be removed to streamline code.
Consider assigning values for the variables before its first use.
For more information visit
Example script:
1 2 3 4 5 6 7 8 9 10 11 12 |
DECLARE @FirstGoodVAR int; DECLARE @SecondGoodVAR int; DECLARE @ThirdGoodVAR int; DECLARE @FourthGoodVAR int; DECLARE @FifthGoodVAR int; DECLARE @FirstFailedVAR int; DECLARE @SecondFailedVAR int; DECLARE @ThirdFailedVAR int; DECLARE @ResultVAR int; SET @ResultVAR = @FirstGoodVAR + @SecondGoodVAR + @ThirdGoodVAR + @FourthGoodVAR + @FifthGoodVAR; |
Message:
Variable @’*’FailedVAR is declared but not used
APX1143 – Potential “unfinished” development
Description:
The presence of keywords like, TEST, TODO, HACK and UNDONE in comments can indicate unfinished work has migrated to Test or Production.
Edit the rule to add/update/remove key words
Example script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
CREATE PROCEDURE proc_UnfinishFirstFailedEx AS BEGIN --TODO SELECT * FROM FirstTable; END; GO CREATE PROCEDURE UnfinishSecondFailedEx AS BEGIN --HACK SELECT * FROM SecondTable; END; GO CREATE PROCEDURE UnfinishThirdFailedEx AS BEGIN --UNDONE SELECT * FROM ThirdTable; END; GO CREATE PROCEDURE UnfinishFirstGoodEx AS BEGIN SELECT * FROM FirstTable; END; GO CREATE PROCEDURE UnfinishSecondGoodEx AS BEGIN SELECT * FROM SecondTable; END; GO |
Message:
Potential unfinished work detected – ‘*’
APX1146 – Unused variable
Description:
This rule evaluates the T-SQL script for never using the variables, even if they are assigned, where these variables should be removed to streamline code.
Make sure to declare only the variables that you need in your code and remove all unused variables.
For more information visit
Example script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
DECLARE @FirstFailedVAR INT; DECLARE @SecondFailedVAR INT; DECLARE @ThirdFailedVAR INT; DECLARE @FourthFailedVAR INT; DECLARE @FifthFailedVAR INT; DECLARE @FirstGoodVAR INT; DECLARE @SecondGoodVAR INT; SET @FirstFailedVAR = 3; SET @SecondFailedVAR = 4; SET @ThirdFailedVAR = 3; SET @FourthFailedVAR = 4; SET @FifthFailedVAR = 5; SET @FirstGoodVAR = 12; SET @SecondGoodVAR = @FirstGoodVAR * 6; SELECT * FROM FirstTable WHERE val = @SecondGoodVAR; PRINT @FifthFailedVAR; SET @FifthFailedVAR = 25; |
Message:
Unused variable, @bad1, detected
APX1190 – Output parameter never assigned
Description:
This rule evaluates the T-SQL script for not assigning values to the output parameters.
Make sure to assign value to the SP OUTPUT parameters.
For more information visit
Example script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
CREATE PROCEDURE proc_OUTParamNoAssignFirstFailedEx @param1 NVARCHAR(30), @param2 INT OUTPUT AS BEGIN SELECT * FROM FirstTable WHERE col1 = @param1; END; GO CREATE PROCEDURE OUTParamNoAssignSecondFailedEx @param1 NVARCHAR(30), @param2 INT OUTPUT, @param3 INT OUTPUT AS BEGIN SELECT * FROM FirstTable WHERE col1 = @param1; END; GO CREATE PROCEDURE OUTParamNoAssignThirdFailedEx @param1 NVARCHAR(30), @param2 INT OUTPUT, @param3 INT OUTPUT AS BEGIN SELECT * FROM FirstTable WHERE col1 = @param1; SET @param3 = @@ROWCOUNT; END; GO CREATE PROCEDURE OUTParamNoAssignFirstGoodEx @param1 NVARCHAR(30), @param2 INT OUTPUT, @param3 INT OUTPUT AS BEGIN SELECT * FROM FirstTable WHERE col1 = @param1; SET @param2 = 115; SET @param3 = @@ROWCOUNT; END; GO CREATE PROCEDURE OUTParamNoAssignSecondGoodEx @param1 NVARCHAR(30), @param2 INT OUTPUT, @param3 INT OUTPUT AS BEGIN SELECT * FROM FirstTable WHERE col1 = @param1; SET @param2 = 125; SET @param3 = @@ROWCOUNT; END; GO |
Message:
Output parameter, @param’*’, isn’t used
APX1203 – Duplicate identifier
Description:
This rule evaluates the T-SQL script for using the same name for different objects.
Try to use unique names for the different database objects.
Example script:
1 2 3 4 5 6 7 |
CREATE TABLE foo(foo1 INT NOT NULL); CREATE INDEX foo ON foo(foo1); CREATE TABLE AA (AA INT, BB INT ); CREATE INDEX AA ON AA(AA, BB); |
Message:
Object [foo] already exists
APX1224 – Comment header
Description:
This rule evaluates the T-SQL script for NOT using comment header blocks.
Comment header improve code maintainability by making the programmability object self-documenting.
For more information visit
https://sqlserverfunctions.wordpress.com/2014/10/13/t-sql-code-header-comments/
Example script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
CREATE PROCEDURE proc_CommentHeaderFirstGoodEx AS BEGIN --Comment for FirstGoodProc DECLARE MyFirstGoodCursor CURSOR LOCAL FOR SELECT * FROM FirstTable; OPEN MyFirstGoodCursor; FETCH NEXT FROM MyFirstGoodCursor; CLOSE MyFirstGoodCursor; DEALLOCATE MyFirstGoodCursor; END; GO CREATE PROCEDURE proc_CommentHeaderSecondGoodEx AS BEGIN --Comment for SecondGoodProc DECLARE MySecondGoodCursor CURSOR GLOBAL READ_ONLY FOR SELECT * FROM SecondTable; OPEN MySecondGoodCursor; FETCH NEXT FROM MySecondGoodCursor; CLOSE MySecondGoodCursor; DEALLOCATE MySecondGoodCursor; END; GO CREATE PROCEDURE proc_CommentHeaderFirstFailedEx AS BEGIN DECLARE MyFirstFailedCursor CURSOR FOR SELECT * FROM FirstTable; OPEN MyFirstFailedCursor; FETCH NEXT FROM MyFirstFailedCursor; END; GO CREATE PROCEDURE proc_CommentHeaderSecondFailedEx AS BEGIN DECLARE MySecondFailedCursor CURSOR FOR SELECT * FROM FirstTable; OPEN MySecondFailedCursor; FETCH NEXT FROM MySecondFailedCursor; END; GO CREATE PROCEDURE proc_CommentHeaderThirdFailedEx AS BEGIN DECLARE MyThirdFailedCursor CURSOR FOR SELECT * FROM FirstTable; OPEN MyThirdFailedCursor; FETCH NEXT FROM MyThirdFailedCursor; CLOSE MyThirdFailedCursor; END; GO |
Message:
Comment header is missing for this CreateProcedure
- Best author award in 2021 - January 3, 2022
- Best author award in 2020 - January 5, 2021
- Best author award in 2019 - January 3, 2020