SQL rules
tx0 checks .sql files with 201 rules, 49 of them in the default tier. Files that say a tool generated them are skipped. Each rule's page explains what it finds and what it leaves alone.
Default: 49 rules
Bugs and security problems with measured precision. They run without a tx0.toml.
-
tx0/sql:aggregate-in-wheredefaultAn aggregate function is used in
WHEREor a join condition -
tx0/sql:application-error-rangedefaultRAISE_APPLICATION_ERRORis given an error number outside -20999 to -20000 -
tx0/sql:arithmetic-with-nulldefaultAn arithmetic or concatenation operand is the literal NULL, so the result is always NULL
-
tx0/sql:between-reversed-boundsdefaultThe lower bound of
BETWEENis greater than the upper bound, so the test is never true -
tx0/sql:case-when-nulldefaultA simple
CASEhas aWHEN NULLbranch, which is never taken -
tx0/sql:coalesce-single-argumentdefaultCOALESCEis called with one argument, so it has no fallback -
tx0/sql:commit-in-triggerdefaultA trigger commits or rolls back the transaction of the statement that fired it
-
tx0/sql:constant-assigneddefaultA PL/SQL constant is assigned a value
-
tx0/sql:count-in-existsdefaultEXISTStests a query that aggregates without grouping, which always returns a row -
tx0/sql:declaration-orderdefaultA MySQL
DECLAREcomes after a statement, or out of the order variables, cursors, handlers -
tx0/sql:division-by-zerodefaultA value is divided by the constant zero
-
tx0/sql:duplicate-column-definitiondefaultA table defines the same column twice
-
tx0/sql:duplicate-cte-namedefaultTwo common table expressions of one
WITHclause have the same name -
tx0/sql:duplicate-exception-handlerdefaultTwo handlers of one block catch the same exception
-
tx0/sql:duplicate-if-conditiondefaultAn
ELSIFtests the same condition as an earlier branch, so it is never taken -
tx0/sql:duplicate-insert-columndefaultThe column list of an
INSERTnames a column twice -
tx0/sql:duplicate-set-columndefaultA
SETclause assigns the same column twice -
tx0/sql:duplicate-table-aliasdefaultTwo tables of one
FROMclause have the same alias or name -
tx0/sql:duplicate-when-branchdefaultA
CASEtests the same condition twice, so the later branch is never taken -
tx0/sql:executesql-non-unicodedefaultsp_executesqlis given its statement as a string literal without theNprefix -
tx0/sql:format-argument-countdefaultA
formatcall orRAISEmessage has a different number of placeholders than arguments -
tx0/sql:identical-function-argumentsdefaultNULLIF,COALESCE,NVLorISNULLis given the same expression twice -
tx0/sql:identical-if-branchesdefaultThe branches of an
IFand itsELSEare the same code -
tx0/sql:identical-operandsdefaultBoth operands of a comparison, logical or arithmetic operator are the same expression
-
tx0/sql:in-parameter-assigneddefaultA PL/SQL
INparameter is assigned a value -
tx0/sql:insert-select-column-countdefaultThe query of an
INSERT ... SELECTreturns a different number of columns than the column list names -
tx0/sql:insert-value-countdefaultA row of an
INSERThas a different number of values than the column list has columns -
tx0/sql:join-without-conditiondefaultA join other than a cross or natural join has no
ONorUSINGcondition -
tx0/sql:label-mismatchdefaultThe label after
END LOOPdiffers from the label of the loop -
tx0/sql:legacy-outer-joindefaultAn outer join is written with
*=or=*, which SQL Server no longer accepts -
tx0/sql:legacy-raiserrordefaultRAISERRORis written in the old form without parentheses, which SQL Server removed -
tx0/sql:loop-index-assigneddefaultThe index of a numeric
FORloop is assigned inside the loop -
tx0/sql:nested-aggregatedefaultAn aggregate function is applied to another aggregate of the same query
-
tx0/sql:not-in-null-literaldefaultA
NOT INlist holds NULL, so the test is never true -
tx0/sql:null-comparisondefaultA value is compared with NULL using
=or<>, which is never true -
tx0/sql:others-handler-not-lastdefaultA
WHEN OTHERShandler is followed by other handlers -
tx0/sql:return-value-in-proceduredefaultA PL/SQL or MySQL procedure returns a value
-
tx0/sql:row-reference-in-statement-triggerdefaultAn Oracle statement-level trigger refers to
:NEWor:OLD -
tx0/sql:rownum-before-orderdefaultROWNUMlimits rows in the same query that sorts them, so the limit applies before the sort -
tx0/sql:rownum-never-matchesdefaultA test such as
ROWNUM > 1orROWNUM = 2can never be true -
tx0/sql:select-into-count-mismatchdefaultA
SELECT ... INTOselects a different number of values than it has variables -
tx0/sql:set-operation-column-countdefaultThe queries of
UNION,INTERSECTorEXCEPTreturn different numbers of columns -
tx0/sql:string-additiondefaultTwo strings are joined with
+in a dialect where+adds numbers -
tx0/sql:subquery-column-countdefaultA single value is compared with a subquery that returns several columns
-
tx0/sql:unreachable-codedefaultA statement follows a
RETURN,RAISE,GOTOorEXITand never runs -
tx0/sql:unterminated-before-withdefaultA T-SQL statement starting with
WITHorTHROWfollows a statement not ended by; -
tx0/sql:values-row-lengthdefaultThe rows of a
VALUESlist have different numbers of values -
tx0/sql:when-others-then-nulldefaultA
WHEN OTHERShandler does nothing, so every error is silently discarded -
tx0/sql:window-function-in-wheredefaultA window function is used in
WHERE, where it cannot be computed
Recommended: 63 rules
Likely bugs, resource and performance problems.
-
tx0/sql:aggregate-without-group-byrecommendedA select list mixes aggregates with plain columns and the query has no
GROUP BY -
tx0/sql:ambiguous-columnrecommendedAn unqualified column exists in more than one table of the query
-
tx0/sql:ambiguous-date-literalrecommendedA date literal in day-month or month-day order is read differently by session settings
-
tx0/sql:ansi-nulls-offrecommendedANSI_NULLSorQUOTED_IDENTIFIERis turned off, which is deprecated and changes comparisons -
tx0/sql:cascade-removalrecommendedTRUNCATEorDROPwithCASCADEalso removes dependent tables or objects -
tx0/sql:case-statement-without-elserecommendedA
CASEstatement has noELSE, so an unmatched value raises an error -
tx0/sql:coalesce-null-argumentrecommendedA fallback function such as
COALESCEis given NULL as a fallback -
tx0/sql:commit-in-looprecommendedA transaction is committed inside a loop
-
tx0/sql:conversion-without-formatrecommendedA string is converted to a date without a format mask, so the session's settings decide
-
tx0/sql:count-for-existencerecommendedRows are counted only to test whether any exist
-
tx0/sql:cursor-not-closedrecommendedA cursor is opened in a routine that never closes it
-
tx0/sql:duplicate-select-aliasrecommendedTwo columns of a select list have the same alias
-
tx0/sql:dynamic-sql-injectionrecommendedDynamic SQL is built by concatenating a routine parameter into the statement text
-
tx0/sql:empty-catch-blockrecommendedA
CATCHblock is empty, so errors are silently discarded -
tx0/sql:empty-string-comparisonrecommendedA value is compared with
'', which Oracle treats as NULL, so the comparison is never true -
tx0/sql:end-name-mismatchrecommendedThe name after
ENDdiffers from the name of the subprogram or package it ends -
tx0/sql:exception-swallowedrecommendedA
WHEN OTHERShandler neither raises the error again nor records it -
tx0/sql:format-unquoted-valuerecommendedDynamic SQL built with
formatpastes a value with%sinstead of quoting it with%Lor%I -
tx0/sql:function-without-returnrecommendedA function body has no
RETURNstatement -
tx0/sql:grant-to-publicrecommendedA privilege is granted to
PUBLIC, that is to every user -
tx0/sql:group-by-nonaggregatedrecommendedA selected column is neither grouped nor aggregated in a grouped query
-
tx0/sql:hardcoded-passwordrecommendedA user, login or role is created or changed with a password written in the script
-
tx0/sql:identical-case-resultsrecommendedEvery branch of a
CASEexpression gives the same result -
tx0/sql:identity-globalrecommended@@IDENTITYis read, which may return an identity made by a trigger -
tx0/sql:implicit-conversionrecommendedA column is compared with a literal of another type, which forces a conversion
-
tx0/sql:in-null-literalrecommendedAn
INlist holds NULL, which matches nothing -
tx0/sql:in-subquery-outer-columnrecommendedThe subquery of
INselects a column of the outer query instead of its own table -
tx0/sql:join-condition-one-sidedrecommendedThe condition of a join does not refer to the table being joined
-
tx0/sql:left-join-filtered-in-whererecommendedA
WHEREcondition on the table of aLEFT JOINremoves the rows the join adds -
tx0/sql:like-matches-everythingrecommendedA
LIKEpattern of only%matches every value that is not NULL -
tx0/sql:like-without-wildcardrecommendedA
LIKEpattern has no wildcard, so it tests for equality -
tx0/sql:limit-without-order-in-changerecommendedAn
UPDATEorDELETElimits its rows withoutORDER BY, so which rows change is arbitrary -
tx0/sql:loop-without-exitrecommendedA loop has no way out: no exit, return, jump or raised error, and its condition is always true
-
tx0/sql:merge-without-terminatorrecommendedA T-SQL
MERGEstatement does not end with; -
tx0/sql:mysql-utf8-charsetrecommendedA MySQL character set or collation is
utf8, which holds only three bytes per character -
tx0/sql:nolock-hintrecommendedA query reads uncommitted data through
NOLOCKorREAD UNCOMMITTED -
tx0/sql:not-in-nullable-subqueryrecommendedNOT INtests a subquery whose column may be NULL, which makes the test never true -
tx0/sql:not-null-column-without-defaultrecommendedA
NOT NULLcolumn without a default is added to an existing table -
tx0/sql:not-null-variable-without-valuerecommendedA PL/SQL
NOT NULLvariable or constant is declared without an initial value -
tx0/sql:null-test-on-not-null-columnrecommendedIS NULLtests a column that the file declaresNOT NULL, so the test is never true -
tx0/sql:order-by-in-subqueryrecommendedA subquery, view or common table expression is ordered without a row limit, so the order is lost
-
tx0/sql:reraise-outside-handlerrecommendedA bare
RAISEorTHROW, which raises the current error again, is outside an error handler -
tx0/sql:reverse-loop-boundsrecommendedA numeric
FORloop has its lower bound above its upper bound, so it never runs -
tx0/sql:security-definer-search-pathrecommendedA PostgreSQL
SECURITY DEFINERroutine does not set its ownsearch_path -
tx0/sql:select-without-from-oraclerecommendedAn Oracle query has no
FROMclause, which versions before 23 reject -
tx0/sql:self-assignmentrecommendedA column or variable is assigned its own value
-
tx0/sql:shell-command-procedurerecommendedSQL Server runs or enables operating system commands through
xp_cmdshell -
tx0/sql:string-type-without-lengthrecommendedA T-SQL string or binary type has no length, so values are cut to 1 or 30 characters
-
tx0/sql:top-percent-orderrecommendedA view orders its rows with
TOP 100 PERCENT ... ORDER BY, which SQL Server ignores -
tx0/sql:transaction-control-in-functionrecommendedA function commits or rolls back a transaction
-
tx0/sql:transaction-not-committedrecommendedA routine begins a transaction and never commits or rolls it back
-
tx0/sql:trigger-returns-resultsrecommendedA T-SQL trigger returns rows to the client of the statement that fired it
-
tx0/sql:trigger-single-rowrecommendedA T-SQL trigger reads
insertedordeletedinto a variable, as if one row changed -
tx0/sql:trustworthy-databaserecommendedA SQL Server database is marked
TRUSTWORTHY, which lets its code act on the whole server -
tx0/sql:undeclared-variablerecommendedA T-SQL variable is used in a batch or routine that does not declare it
-
tx0/sql:unguarded-rollbackrecommendedA
CATCHblock rolls back without checking that a transaction is open -
tx0/sql:unknown-table-referencerecommendedA column is qualified with a name that is not a table or alias of the query
-
tx0/sql:unread-variablerecommendedA local variable is assigned but its value is never read
-
tx0/sql:unused-cterecommendedA common table expression is defined but never used
-
tx0/sql:unused-cursorrecommendedA cursor is declared but never used
-
tx0/sql:unused-exceptionrecommendedAn exception is declared but never raised or handled
-
tx0/sql:unused-variablerecommendedA local variable is declared but never used
-
tx0/sql:view-select-starrecommendedA view selects
*, whose columns are fixed when the view is created
Strict: 89 rules
Code that can be written more plainly.
-
tx0/sql:ad-hoc-remote-querystrictA query connects to another data source with
OPENROWSETorOPENDATASOURCE -
tx0/sql:automation-procedurestrictT-SQL calls OLE Automation or registry procedures, which act with the server's rights
-
tx0/sql:blocking-index-creationstrictA PostgreSQL index is created without
CONCURRENTLY, which blocks writes to the table -
tx0/sql:boolean-expression-complexitystrictA condition combines more
ANDandORoperators than the configured maximum -
tx0/sql:boolean-literal-comparisonstrictA value is compared with
TRUEorFALSE -
tx0/sql:bulk-collect-without-limitstrictA
FETCH ... BULK COLLECTloads every row of a cursor at once, withoutLIMIT -
tx0/sql:case-without-elsestrictA
CASEexpression has noELSE, so unmatched values give NULL -
tx0/sql:char-variablestrictA PL/SQL variable or parameter is declared as
CHARorVARCHARinstead ofVARCHAR2 -
tx0/sql:column-countstrictA table has more columns than the configured maximum
-
tx0/sql:column-drop-or-renamestrictA migration drops or renames a column that running code may still use
-
tx0/sql:comma-joinstrictTables are joined by commas in
FROM -
tx0/sql:commented-out-codestrictA comment holds a statement that was commented out
-
tx0/sql:console-outputstrictStored code writes to
DBMS_OUTPUT -
tx0/sql:constant-conditionstrictA condition compares two constants
-
tx0/sql:cross-database-referencestrictA table is named with its database or server
-
tx0/sql:cursor-loopstrictRows are changed one at a time in a loop over a cursor or query
-
tx0/sql:cyclomatic-complexitystrictA routine has more paths through it than the configured maximum
-
tx0/sql:delete-without-wherestrictA
DELETEhas noWHEREclause and removes every row -
tx0/sql:deprecated-large-typestrictA deprecated large object type such as
text,imageorLONGis used -
tx0/sql:distinct-in-subquerystrictA subquery of
INorEXISTSremoves duplicates that do not matter -
tx0/sql:distinct-with-group-bystrictA grouped query also removes duplicates with
DISTINCT -
tx0/sql:double-negationstrictA condition is negated twice
-
tx0/sql:drop-without-if-existsstrictAn object is dropped without
IF EXISTS -
tx0/sql:empty-then-branchstrictThe
THENbranch of anIFdoes nothing and only itsELSEbranch acts -
tx0/sql:enum-columnstrictA column has an
ENUMtype -
tx0/sql:error-variable-checkstrictErrors are handled by testing
@@ERRORinstead ofTRY ... CATCH -
tx0/sql:exec-string-variablestrictEXECruns a string built in a variable instead ofsp_executesqlwith parameters -
tx0/sql:explicit-table-lockstrictA whole table is locked explicitly
-
tx0/sql:file-lengthstrictA file has more lines of code than the configured maximum
-
tx0/sql:float-for-moneystrictA column named as an amount of money has a floating-point type
-
tx0/sql:foreign-keys-disabledstrictForeign key checks are turned off
-
tx0/sql:function-on-columnstrictA
WHEREcondition applies a function to a column before comparing it with a constant -
tx0/sql:global-cursorstrictA T-SQL cursor is declared without
LOCALand is global to the session -
tx0/sql:global-temp-tablestrictA global temporary table shared by all sessions is used
-
tx0/sql:goto-statementstrictA
GOTOstatement jumps to a label -
tx0/sql:grant-all-privilegesstrictGRANT ALLgives every privilege where a few would do -
tx0/sql:grant-with-grant-optionstrictA privilege is granted with the right to grant it to others
-
tx0/sql:having-without-aggregatestrictA
HAVINGcondition uses no aggregate and belongs inWHERE -
tx0/sql:implicit-aliasstrictA column alias is written without
AS -
tx0/sql:inconsistent-not-equalstrictA file writes not-equal both as
<>and as!= -
tx0/sql:index-hintstrictA query forces the choice of an index
-
tx0/sql:insert-select-starstrictAn
INSERTcopies rows withSELECT *, matching columns by position -
tx0/sql:insert-without-columnsstrictAn
INSERThas no column list and relies on the order of the table's columns -
tx0/sql:isnumeric-functionstrictISNUMERICis used, which accepts strings that do not convert to a number -
tx0/sql:join-countstrictA query joins more tables than the configured maximum
-
tx0/sql:keyword-case-mixedstrictKeywords are written in both upper and lower case in one file
-
tx0/sql:large-in-liststrictAn
INlist holds more values than the configured maximum -
tx0/sql:leading-wildcard-likestrictA
LIKEpattern starts with a wildcard, so no index on the column helps -
tx0/sql:limit-without-orderstrictA query limits its rows without
ORDER BY, so which rows it returns is arbitrary -
tx0/sql:line-lengthstrictA line is longer than the configured maximum
-
tx0/sql:missing-end-namestrictA PL/SQL subprogram ends without repeating its name
-
tx0/sql:missing-nocountstrictA T-SQL procedure does not turn on
NOCOUNT -
tx0/sql:mixed-and-orstrictANDandORare mixed without parentheses -
tx0/sql:multiple-statements-per-linestrictA line holds more than one statement
-
tx0/sql:mysql-display-widthstrictA MySQL integer type has a display width, which is deprecated and limits nothing
-
tx0/sql:mysql-storage-enginestrictA MySQL table uses the
MyISAMengine, which has no transactions -
tx0/sql:negated-comparisonstrictA comparison is negated instead of inverted
-
tx0/sql:nested-casestrictCASEexpressions are nested deeper than the configured maximum -
tx0/sql:nesting-depthstrictControl statements are nested deeper than the configured maximum
-
tx0/sql:or-in-join-conditionstrictA join condition combines comparisons with
OR -
tx0/sql:parameter-countstrictA routine takes more parameters than the configured maximum
-
tx0/sql:plaintext-password-columnstrictA table has a text column named as a password, which suggests passwords stored as typed
-
tx0/sql:positional-referencestrictORDER BYorGROUP BYrefers to a column by its position -
tx0/sql:postgres-type-choicestrictA PostgreSQL column uses
money,char(n),timestampwithout time zone orserial -
tx0/sql:random-orderstrictRows are sorted by a random value
-
tx0/sql:redundant-aliasstrictA table is aliased to its own name
-
tx0/sql:redundant-boolean-casestrictA
CASEmaps a condition toTRUEandFALSE, which the condition is already -
tx0/sql:return-countstrictA routine has more
RETURNstatements than the configured maximum -
tx0/sql:rewrite-rulestrictA PostgreSQL rewrite rule is created
-
tx0/sql:routine-lengthstrictA function, procedure or trigger has more lines of code than the configured maximum
-
tx0/sql:schema-unqualified-procedure-callstrictA T-SQL procedure is called without its schema
-
tx0/sql:select-starstrictA query selects
*instead of the columns it needs -
tx0/sql:set-rowcountstrictSET ROWCOUNTlimits the rows of every following statement -
tx0/sql:single-value-in-liststrictAn
INlist holds a single value -
tx0/sql:sqlite-autoincrementstrictA SQLite key uses
AUTOINCREMENT, which costs on every insert -
tx0/sql:statement-without-terminatorstrictA T-SQL statement does not end with
; -
tx0/sql:string-literal-aliasstrictA column alias is written as a string literal
-
tx0/sql:subquery-depthstrictSubqueries are nested deeper than the configured maximum
-
tx0/sql:system-procedure-prefixstrictA T-SQL procedure is named with the
sp_prefix of system procedures -
tx0/sql:table-without-primary-keystrictA table is created without a primary key
-
tx0/sql:todo-commentstrictA comment marks work left to do
-
tx0/sql:uncorrelated-existsstrictAn
EXISTSfilter of a query does not refer to the query, so it keeps all rows or none -
tx0/sql:unicode-literal-without-prefixstrictA T-SQL string literal with characters outside ASCII has no
Nprefix -
tx0/sql:unqualified-column-in-joinstrictA query over several tables names a column without its table
-
tx0/sql:unused-labelstrictA label is never referred to
-
tx0/sql:unused-parameterstrictA routine never uses one of its parameters
-
tx0/sql:update-without-wherestrictAn
UPDATEhas noWHEREclause and changes every row -
tx0/sql:waitfor-delaystrictA statement waits for a fixed time with
WAITFOR DELAYorpg_sleep -
tx0/sql:weak-hashstrictA value is hashed with MD5 or SHA-1