PhpStorm 2022.2 Help

Code Inspections in SQL server

This topic lists all PhpStorm code inspections available in SQL server.

You can toggle specific inspections or change their severity level on the Editor | Inspections page of the IDE settings Ctrl+Alt+S.

Inspection

Description

Default Severity

Builtin functions

Reports truncations of string arguments in ISNULL functions.

The ISNULL syntax is ISNULL(check_expression, replacement_value).

According to ISNULL at docs.microsoft.com, replacement_value will be truncated if replacement_value is longer than check_expression.

Example (Microsoft SQL Server):

DECLARE @name1 VARCHAR(2) = NULL; DECLARE @name2 VARCHAR(10) = 'Example'; DECLARE @name3 VARCHAR(2) = 'Hi'; -- `@name2` is VARCHAR(10) and will be truncated SELECT ISNULL(@name1, @name2); -- `@name3` is VARCHAR(2) as `@name1` and will not be truncated SELECT ISNULL(@name1, @name3);

Warning Warning

ORDER BY in queries

Reports usages when the ORDER BY clause is used without TOP, OFFSET, or FOR XML in views, inline functions, derived tables, subqueries, and common table expressions.

For more information about usages of ORDER BY, see SELECT - ORDER BY Clause (Transact-SQL) at docs.microsoft.com.

Example (Microsoft SQL server):

CREATE TABLE foo (a INT NOT NULL, b INT NOT NULL); SELECT * FROM (SELECT a, b FROM foo A WHERE a < 89 ORDER BY b) ALIAS;

In a subquery, ORDER BY will be highlighted as an error. You can add TOP, OFFSET, or FOR XML to a subquery. Alternatively, use the Delete element quick-fix to delete the ORDER BY section.

After the quick-fix is applied:

SELECT * FROM (SELECT a, b FROM foo A WHERE a < 89) ALIAS;

Error Error

Last modified: 13 May 2022