SQL Formatter Options
Options
Stored Procedures / Parms
The Procedure/Function Parameters Options in the SQL Formatter Tool allow you to configure the formatting of parameters in stored procedures or functions. These settings provide control over line breaks, indentation, and alignment for better readability and organization.
Parms / Line
Parms / Line
- Specifies how many parameters are displayed on each line.
- Example: Setting this to
1
ensures each parameter is placed on a new line, while larger values allow multiple parameters per line.
Before Comma / After Comma
- Before Comma: Adds a line break before commas separating parameters.
- After Comma: Adds a line break after commas separating parameters.
Indent Parms
- Indents all parameters to align them visually within the parameter list.
Parentheses
Before „(“ / After „(„
- Before „(„: Adds a line break before the opening parenthesis in the parameter list.
- After „(„: Adds a line break after the opening parenthesis.
Before „)“ / After „)“
- Before „)“: Adds a line break before the closing parenthesis in the parameter list.
- After „)“: Adds a line break after the closing parenthesis.
How to Use These Settings
Set Parameters Per Line
- Adjust the Parms / Line dropdown to control the number of parameters per line, ensuring better readability for procedures or functions with long parameter lists.
Control Comma Placement
- Enable Before Comma or After Comma to manage line breaks around commas for separating parameters.
Enable Indentation
- Use Indent Parms to align all parameters neatly, making the code easier to scan and understand.
Customize Parenthesis Placement
- Use the checkboxes for Before „(„, After „(„, Before „)“, and After „)“ to add line breaks around parentheses and create a clear structure.
Tips for Optimal Usage
- Set Parms / Line to
1
for procedures or functions with many parameters to ensure each parameter is displayed on its own line. - Use After Comma for better separation and readability when listing multiple parameters.
- Enable Indent Parms to create a visually aligned and clean parameter list.
- Add line breaks around parentheses for complex parameter lists to enhance clarity.
Stored Procedures / Conditions
The IF and Conditions Options in the SQL Formatter Tool allow you to customize the formatting of conditional statements (IF
, THEN
, ELSE
) and related constructs. These settings ensure that conditions are formatted clearly and consistently, enhancing readability and maintainability.
IF and THEN/ELSE Formatting
IF
- Adds a line break before or after the
IF
keyword to structure conditional statements.
- Adds a line break before or after the
THEN
- Adds a line break before or after the
THEN
keyword for better separation. - Indent THEN: Indents the
THEN
block to align it hierarchically with theIF
statement.
- Adds a line break before or after the
After ELSE
- Adds a line break after the
ELSE
keyword to clearly separate it from subsequent content. - Indent ELSE: Indents the
ELSE
block for better visual structure.
- Adds a line break after the
Conditions
Open „(“ / Close „)“
- Open „(„: Adds a line break before the opening parenthesis in conditions.
- Close „)“: Adds a line break after the closing parenthesis for improved readability.
AND/OR
- Adds a line break before logical operators (
AND
/OR
) in conditional statements for clarity.
- Adds a line break before logical operators (
Indent Conditions in Brackets
- Indents conditions enclosed within parentheses to align them with the surrounding structure.
Align Compare Operators (<, >, =, …)
- Aligns comparison operators (e.g.,
<
,>
,=
) to create a clean and visually consistent layout.
- Aligns comparison operators (e.g.,
BEGIN/END
- Indent BEGIN … END
- Indents the
BEGIN
andEND
blocks to reflect the nested structure of procedural SQL. - This ensures that all statements within the block are visually grouped.
- Indents the
How to Use These Settings
Enable Line Breaks for Keywords
- Use the checkboxes for IF, THEN, and ELSE to define where line breaks are added around these keywords.
Customize Indentation
- Enable Indent THEN and Indent ELSE to structure the blocks for hierarchical alignment.
- Use Indent Conditions in Brackets to format conditions neatly within parentheses.
Control Parenthesis and Logical Operators
- Use Open „(„ and Close „)“ to separate parenthesis-enclosed conditions.
- Add line breaks with AND/OR to clearly distinguish logical conditions.
Align Operators
- Enable Align Compare Operators (<, >, =, …) to create visually consistent conditional statements.
Indent BEGIN/END Blocks
- Use the Indent BEGIN … END option to ensure procedural blocks are aligned and easy to follow.
Tips for Optimal Usage
- Use Indent THEN and Indent ELSE for a clear hierarchical structure in conditional statements.
- Enable Align Compare Operators to ensure conditions are easy to read, especially in complex queries.
- Add line breaks with AND/OR to separate logical operators and improve readability.
- Indent BEGIN … END blocks to reflect their nested nature and maintain clarity in procedural SQL.
Stored Procedures / Variables
The Variables Options in the SQL Formatter Tool allow you to format and align variable declarations and assignments consistently in stored procedures and functions. These settings help ensure clarity and organization in variable-related SQL code.
Available Options
Align Variable Declaration
- Ensures that all variable declarations (
DECLARE
) are aligned vertically in the SQL script. - This makes it easier to scan and understand declared variables, especially in complex stored procedures.
- Ensures that all variable declarations (
Align Variable Association Operator (
=>
)- Aligns the association operator (
=>
) used in constructs like parameter passing or key-value pairs in certain SQL contexts. - Ensures consistent alignment when multiple association operators are used.
- Aligns the association operator (
Align Assignment Operator (
:=
,=
,*=
,.=
, etc.)- Aligns assignment operators used for assigning values to variables.
- This includes different operators like
:=
(PL/SQL),=
(T-SQL or standard SQL), and others. - Helps create a clean and visually structured code layout for assignments.
Extract from Source Code / Generate Source Code
The Extract & Generate Options in the SQL Formatter Tool provide functionality to extract SQL statements from source code (e.g., Java, C#) and generate source code in various programming languages based on formatted SQL. These features are essential for integrating SQL with application code efficiently.
Extract SQL from Source Code
SQL in Source Code Between
- Defines the delimiters or markers that indicate the start and end of SQL code within the source code.
- Example: SQL statements in Java might be enclosed in double quotes (
"SELECT * FROM table;"
).
Always „Extract SQL“ Before „Format SQL“
- When enabled, the tool will automatically extract SQL from the source code before applying any formatting.
- This ensures that only valid SQL statements are formatted.
Extract SQL
- Click this button to extract SQL code from the source code based on the specified delimiters.
- The extracted SQL can then be formatted using the tool.
Generate Source Code
Always „Generate Code“ After „Format SQL“
- When enabled, the tool automatically generates source code after formatting the SQL.
- This ensures that the formatted SQL is seamlessly reintegrated into the source code.
Language
- Select the target programming language for generating source code (e.g., Java, C#, etc.).
- This setting adapts the generated code to match the syntax and conventions of the chosen language.
Generate
- Click this button to generate source code based on the formatted SQL and the selected programming language.
- The tool ensures proper escaping and syntax adjustments for the target language.
Simulation
- Allows you to simulate the source code generation process without making any actual changes.
- Useful for previewing the generated output before applying it to your project.
How to Use These Features
Extracting SQL
- Specify the delimiters used in your source code to enclose SQL statements in the SQL in Source Code Between field.
- Click Extract SQL to pull out the SQL statements, which can then be formatted.
Formatting SQL
- Use the standard formatting options in the tool to format the extracted SQL statements.
- Ensure Always „Extract SQL“ Before „Format SQL“ is enabled for automatic extraction during formatting.
Generating Source Code
- Select the desired target language in the Language dropdown.
- Click Generate to create source code with the formatted SQL embedded, using the syntax and conventions of the chosen language.
- Use the Simulation button to preview the generated source code before applying it.
Automating the Workflow
- Enable Always „Generate Code“ After „Format SQL“ to streamline the process of formatting SQL and generating source code in one step.
Tips for Optimal Usage
- Delimiters: Ensure the correct delimiters are set in the SQL in Source Code Between field to accurately extract SQL from your source code.
- Language Selection: Choose the appropriate language in the Language dropdown to ensure compatibility with your application code.
- Simulation: Use the Simulation option to verify the generated code before applying it, avoiding potential integration issues.
- Automation: Enable the Always „Extract SQL“ Before „Format SQL“ and Always „Generate Code“ After „Format SQL“ options to automate and speed up repetitive tasks.