Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Anchor
_UNDERSTANDING_AUTOMATIC_ERROR
_UNDERSTANDING_AUTOMATIC_ERROR
Understanding

...

automatic error detection

SQL Editor orders and classifies SQL statements. This enables it to edit code as you work within SQL Editor and highlight errors and typographical errors in "real time". As you work, SQL Editor examines each clause in a statement and provides error reporting and other features as required. 

...

Info

Automatic error detection functions, such as syntax checking and semantic validation are suspended if #define or #include directives are detected in an editor window. SQL Query Tuner does not perform #define/#include substitutions on execution. 

Anchor
_UNDERSTANDING_CODE_ASSIST
_UNDERSTANDING_CODE_ASSIST
Understanding

...

code assist

When SQL Editor has finished analyzing a partial piece of code, it displays a list of data source objects for you to select from.

...

The following table displays a list of all possible object suggestions, and the format in which SQL Editor inserts the suggestions into a statement:

Object and

...

stored procedure suggestions

Object SuggestionSyntax/Example
Table

(TABLE) [catalog].[schema]

EMPLOYEE - (TABLE)HR

Alias Table

(TABLE ALIAS)

[catalog].[schema]tableName

EMPLOYEE - (TABLE ALIAS)HRJOBS

Column

datatype - (Column)

[catalog].[schema].tableName

JOB_TITLE:varchar(20) - (Column)HRJOBS

Alias Column

datatype - (COLUMN ALIAS)

[catalog].[schema].tableName.columnName

JOB_TITLE:int-(COLUMN ALIAS)HR.JOBS.JOB_ID

Schema

(SCHEMA) [catalog]

dbo-(SCHEMA)NorthWind

Catalog(CATALOG)
CallCall HR.ADD_JOB_HISTORY

Function

...

suggestions

Function SuggestionSyntax/Example
Built-inSELECT A FROM HR.DEPARTMENTS WHERE HR.DEPARTMENTS AVG
User-DefinedSELECT + FROM HR.CLIENTS WHERE HR.F_PERSONAL

...

You can speed up the performance of the code assist functionality by enabling data source indexing either when you connect to the data source, see Working with Data Sources or on the Preferences page, see Specify Data Source Indexing Preferences.

...

SQL Editor supports hyperlinks that are activated when a user hovers their mouse over a word and presses the CTRL key. If a hyperlink can be created, it becomes underlined and changes color. When the hyperlink is selected, the creation script for the hyperlink object is opened in a new editor. 

...

Info

Hyperlink functionality relies on certain objects being captured in the Object Index. If the index is turned off, or has been restricted in what information it captures, users will be unable to link them (as they are non-existent within the Index.) To specify object index types, see Specify Data Source Indexing Preferences.

Anchor
_UNDERSTANDING_CODE_FORMATTING
_UNDERSTANDING_CODE_FORMATTING
Understanding

...

code formatting

Code formatting provides automatic code formatting in SQL Editor while you are developing code. 

...

The following examples display a list of code formatting parameters and the resultant output in SQL Editor, based on the same set of SQL statements.

Custom

...

code formatting example 1

The following chart indicates a list of custom code formatting parameters and their corresponding values. The chart is followed by the actual syntax as it would appear in SQL Editor, based on the formatting parameter values.

...

Custom Code Formatting ParameterValue (if applicable)

Stack commas separated by lists?

Yes

Stack Lists with __ or more items.

3

Indent Size?

2

Preceding commas?

Yes

Spaces after comma?

1

Trailing commas?

Spaces before comma?

Right align FROM and WHERE clauses with SELECT statement?

Yes

Align initial values for FROM and
WHERE clauses with SELECT list?

Yes

Place SQL keywords on their own line?

No

Indent size?

Indent batch blocks?

Yes

Number of new lines to insert

1

Indent Size

5

Right Margin?

80

Stacked parentheses when they contain multiple items?

No

Stacked parentheses when the list contains __ or more items.

_

Indent size?

5

New line after first parentheses?

No

Indent content of conditional and looping constructs?

Yes

Number of new lines to insert?

1

Indent size?

5

Image Modified
Custom

...

code formatting example 2

The following chart indicates a list of custom code formatting parameters and corresponding values. The chart is followed by the actual syntax as it would appear in SQL Editor based on the formatting parameter values. Compare the parameters and formatted code in Example 1 with this example for a concept of how custom formatting works.

...

'latin america' ,
'france' ,
'russia' ,
'canada' ,

Anchor
_UNDERSTANDING_CODE_FOLDING
_UNDERSTANDING_CODE_FOLDING
Understanding

...

code folding

SQL Editor features code folding that automatically sorts code into an outline-like structure within the editor window for easy navigation and clarity while developing code. 

...

The editor window automatically inserts collapsible nodes in the appropriate lines of code for organizational purposes. This enables you to expand and collapse statements, as needed, while developing code in particularly large or complicated files.

Anchor
_UNDERSTANDING_CODE_QUALITY
_UNDERSTANDING_CODE_QUALITY
Understanding

...

code quality checks

Code quality markers provide annotations that prevent and fix common mistakes in the code.

...

Code Quality Check Type

Definition
Statement is missing valid JOIN criteria

If a SELECT statement contains missing join criteria, when it is executed, it can produce a Cartesian product between the rows in the referenced tables. This can be problematic because the statement will return a large number of rows without returning the proper results.

The code quality check detects missing join criteria between tables in a statement and suggests join conditions based on existing foreign keys, indexes, and column name/type compatibility.

Example:

The following statement is missing a valid JOIN criteria:

SELECT*FROM employeee,customerc,sales_orders
WHERE e.employee_id = c.salesperson_id

The code quality check fixes the above statement by adding an AND clause:

SELECT*FROM employeee,customerc,sales_orders
WHERE e.employee_id = c.salesperson_id AND s.customer_id = c.customer_id

Info

This code quality check is valid for Oracle , and DB2, and Sybase-specific join conditions.

Invalid or missing outer join operator

When an invalid outer join operator exists in a SELECT statement, (or the outer join operator is missing altogether), the statement can return incorrect results.

The code quality check detects invalid or missing join operators in the code and suggests fixes with regards to using the proper join operators.

Example:

The following statement is missing an outer join operator:

SELECT * FROM employee e, customer c
WHERE e.employee_id=c.salesperson_id(+)ANDc.state=‘CA’

The code quality check fixes the above statement by providing the missing outer join operator to the statement:

SELECT * FROM employee e,customer c
WHERE e.employee_id = c.salesperson_id(+) AND c.state(+) = ‘CA’

Transitivity issues

The performance of statements can sometimes be improved by adding join criteria, even if a join is fully defined. If this alternate join criterion is missing in a statement, it can restrict the selection of an index in Oracle’s optimizer and cause performance problems.

The code quality check detects possible join conditions by analyzing the existing conditions in a statement and calculating the missing, alternative join criteria.

Example:

The following statement contains a transitivity issue with an index problem:

SELECT * FROM item i, product p, price pr
WHERE i.product_id = p.product_id AND p.product_id = pr.product_id

The code quality check fixes the above statement with a transitivity issue by adding the missing join condition:

SELECT * FROM item i, product p, price pr
WHERE i.product_id = p.product_id AND p.product_id = pr.product_id AND i.product_id = pr.product_id\

Nested query in WHERE clause

It is considered bad format to place sub-queries in the WHERE clause of a statement, and such clauses can typically be corrected by moving the sub- query to the FROM clause instead, which preserves the meaning of the statement while providing more efficient code.

The code quality check fixes the placement of sub-queries in a statement, which can affect performance. It detects the possibility of moving sub- queries from the FROM clause of the statement.

Example:

The following statement contains a sub-query that contains an incorrect placement of a WHERE statement:

SELECT*FROM employee
WHERE employee_id=(SELECT MAX(salary) FROM employee)

The code quality check fixes the above statement by correcting the sub- query issue:

SELECT employee.* FROM employee (SELECT DISTINCT MAX(salary) col1 FROM employee) t1
WHERE employee_id = t1.col1

Wrong place for conditions in a HAVING clause

When utilizing the HAVING clause in a statement:

It is recommended to include as few conditions as possible while utilizing the HAVING clause in a statement. SQL Query Tuner detects all conditions in a given HAVING statement and suggests equivalent expressions that can benefit from existing indexes.

Example:

The following statement contains a HAVING clause that is in the wrong place:

SELECT col_a, SUM(col_b) FROM table_a GROUP BY col_a HAVING col_a > 100

The code check fixes the above statement by replacing the HAVING clause with equivalent expressions:

SELECT col_a, SUM(col_b) FROM table_a
WHERE col_a > 100 GROUP BY col_a

Index suppressed by a function or an arithmetic operator

In a SELECT statement, if an arithmetic operator is used on an indexed column in the WHERE clause, the operator can suppress the index and result in a FULL TABLE SCAN that can hinder performance.

The code quality check detects these conditions and suggests equivalent expressions that benefit from existing indexes.

Example:

The following statement includes an indexed column as part of an arithmetic operator:

SELECT * FROM employee
WHERE 1 = employee_id - 5

The code quality check fixes the above statement by reconstructing the WHERE clause:

SELECT * FROM employee
WHERE 6 = employee_id

Mismatched or incompatible column types

When the data types of join or parameter declaration columns are mismatched, the optimizer is limited in its ability to consider all indexes. This can cause a query to be less efficient as the system might select the wrong index or perform a table scan, which affects performance.

The code quality check flags mismatched or incompatible column types and warns that it is not valid code.

Example:

Consider the following statement if Table A contains the column col int and Table B contains the column col 2 varchar(3):

SELECT * FROM a, b
WHERE a.col = b.col;

In the above scenario, the code quality check flags the ‘a.col = b.col’ part of the statement and warns that it is not valid code.

Null column comparison

When comparing a column with NULL, the !=NULL condition may return a result that is different from the intended command, because col=NULL will always return a result of false. Instead, the NULL/IS NOT NULL operators should be used in its place.

The code quality check flags occurrences of the !=NULL condition and replaces them with the IS NULL operator.

Example:

The following statement includes an incorrect col = NULL expression:

SELECT * FROM employee
WHERE manager_id = NULL

The code quality check replaces the incorrect expression with an IS NULL clause:

SELECT * FROM employee
WHERE manager_id IS NULL

Anchor
_UNDERSTANDING_SQL_TEMPLATES
_UNDERSTANDING_SQL_TEMPLATES
Understanding SQL

...

templates

SQL Query Tuner provides code templates for DML and DDL statements that can be applied to the Editor via the (Ctrl + Spacebar) command. When you choose a template from the menu that appears, SQL Editor automatically inserts a block of code with placeholder symbols that you can modify to customize the code for your own purposes. 

...