Automatically Fixing Issues
Published 29 October 2019
As an extension to Code Analysis, SQL Prompt allows you to automatically fix certain issues that are present in your code.
Currently, SQL Prompt supports the automatic fixing of the following issues:
- BP002: ORDER BY clause with constants
- BP004: INSERT without column list
- BP005: Asterisk in SELECT list
- BP006: TOP without ORDER BY
- BP008: CAST/CONVERT to variable-size types without length
- BP009: Avoid variable-size types of length 1 or 2
- BP010: Usage of @@IDENTITY
- BP012: CASE without ELSE
- BP014: [NOT] NULL option is not specified in CREATE/DECLARE TABLE statement
- BP022: Money/SmallMoney datatype is used
- BP023: FLOAT/REAL datatype is used
- DEP021: String literals as column aliases are deprecated
- EI003: Non-scalar subquery in place of a scalar value
- MI003: Unqualified column name
- MI005: Variable is declared but never used
- PE001: Schema name for procedure is not specified
- PE002: Schema name for table or view is not specified
- PE003: Creation of table by SELECT INTO statement
- PE006: Table hint is used
- PE023: DDL without specifying a schema name for table
- SC006: The EOL marker sequence is not the expected CR/LF
- ST002: Old-style column alias via EQUALS sign
- ST003: Enclose procedure body with BEGIN/END
- ST006: Old style TOP clause is used
- ST008: Non-named parameter style used
- ST010: Use alias for all table sources
- ST013: Non-ANSI NOT_EQUAL operator used (!=)
When you left-click an issue present within your code, a light bulb icon will appear in the sidebar:
are automatically fixable
Issues that cannot be fixed automatically
When you click on the light bulb, a menu appears that allows you to apply a fix (when applicable), show more details about the issue, or see a list of all issues in the script.
Note that some fixes will require you to enter additional information. For example, after applying the fix for issue BP006: TOP without ORDER BY, you will need to type the name of the column or expression that you want to use to sort your results.