SQL Formatter Options

Merge

The MERGE Options in the SQL Formatter Tool allow you to configure the formatting of MERGE INTO statements in SQL. These settings enable you to structure the syntax for better readability, consistency, and maintainability.

Sql Formatter Options Merge

MERGE

  1. After MERGE
    • Adds a line break immediately after the MERGE keyword.
    • This ensures a clear separation between the MERGE keyword and the subsequent clauses.

USING

  1. Before USING / After USING

    • Before USING: Adds a line break before the USING keyword.
    • After USING: Adds a line break after the USING keyword.
    • These options improve the structure of the MERGE INTO statement by visually separating the USING clause.
  2. Before ON / After ON

    • Before ON: Adds a line break before the ON clause, which defines the merge condition.
    • After ON: Adds a line break after the ON clause for better clarity.
  3. Before AND/OR / After AND/OR

    • Before AND/OR: Adds a line break before logical operators like AND or OR in the USING clause.
    • After AND/OR: Adds a line break after these operators for better readability.
  4. Indent AND/OR

    • Indents logical operators (AND/OR) to align them with the structure of the USING clause.

WHEN

  1. Before AND/OR / After AND/OR

    • Before AND/OR: Adds a line break before logical operators (AND/OR) in the WHEN clause.
    • After AND/OR: Adds a line break after these operators for improved visibility.
  2. Indent AND/OR

    • Indents logical operators (AND/OR) in the WHEN clause to align them with the clause’s indentation.
  3. Before THEN

    • Adds a line break before the THEN keyword in the WHEN clause for better readability of actions.

Conditions

The Conditions Options in the SQL Formatter Tool allow you to configure how conditions in SQL statements are formatted. These settings control the placement of line breaks, indentation, and logical operator alignment, improving the readability and structure of SQL queries.

Sql Formatter Options Conditions

Brackets

  1. Before „(“ / After „(„

    • Before „(„: Adds a line break before the opening parenthesis in conditions.
    • After „(„: Adds a line break after the opening parenthesis.
  2. Before „)“ / After „)“

    • Before „)“: Adds a line break before the closing parenthesis in conditions.
    • After „)“: Adds a line break after the closing parenthesis.
  3. Indent Condition

    • Indents the conditions within brackets for better alignment and readability.

JOIN

  1. Before AND/OR / After AND/OR

    • Before AND/OR: Adds a line break before logical operators like AND or OR in JOIN conditions.
    • After AND/OR: Adds a line break after these logical operators.
  2. Indent AND/OR

    • Indents logical operators (AND/OR) in JOIN conditions to align them with the structure of the query.

WHERE

  1. Before AND/OR / After AND/OR

    • Before AND/OR: Adds a line break before logical operators in the WHERE clause.
    • After AND/OR: Adds a line break after these operators for better clarity.
  2. Indent AND/OR

    • Indents logical operators (AND/OR) in the WHERE clause for improved visual hierarchy.

CASE

The CASE Options in the SQL Formatter Tool allow you to format CASE statements with precision, ensuring better readability and alignment with coding standards. These settings control indentation, line breaks, and compactness for both simple and complex CASE structures.

Sql Formatter Options Case

CASE Formatting

  1. CASE, WHEN, THEN, ELSE, END

    • Adds line breaks before these keywords in the CASE statement for better clarity and structure.
    • These options ensure each component of the CASE block is properly separated.
  2. Indent CASE inside „()“

    • Indents the entire CASE block when it is enclosed within parentheses.
  3. Indent WHEN, THEN, ELSE

    • Adds indentation to the WHEN, THEN, and ELSE keywords for hierarchical alignment in nested or multi-line CASE statements.

CASE Condition

  1. AND/OR

    • Adds a line break before logical operators (AND, OR) within the CASE conditions to clearly separate them from other conditions.
  2. Open „(“ / Close „)“

    • Open „(„: Adds a line break before the opening parenthesis in CASE conditions.
    • Close „)“: Adds a line break after the closing parenthesis for better visibility of nested conditions.

Small CASE Statements on 1 Line

  1. No Break for CASE < X chars
    • Keeps small CASE statements (e.g., under 10 characters) on a single line for compactness.
    • Adjust the character limit using the -10 and +10 buttons to define what qualifies as a „small“ CASE statement.

Compact vs. Expand

  • Compact: Condenses CASE statements by reducing line breaks and indentation.
  • Expand: Formats CASE statements with more line breaks and indentation for improved readability.

How to Use These Settings

  1. Enable or Disable Line Breaks

    • Use the checkboxes for CASE, WHEN, THEN, ELSE, END to specify where line breaks should be added in CASE blocks.
  2. Customize Indentation

    • Enable indentation options like Indent CASE inside „()“ and Indent WHEN, THEN, ELSE to align keywords hierarchically within the CASE block.
  3. Adjust Logical Conditions

    • Use the AND/OR option to structure complex conditions within CASE statements with line breaks and proper alignment.
  4. Set Character Limits for Compactness

    • Define a character limit for keeping small CASE statements on one line to maintain a balance between compactness and readability.
  5. Switch Between Compact and Expand Modes

    • Use Compact for minimizing line breaks in short CASE blocks and Expand for a detailed, well-structured format.

DDL Create

The Create Table / Create Index Options in the SQL Formatter Tool allow you to format SQL CREATE statements with better structure and readability. These settings control line breaks, indentation, and keyword alignment for table and index creation queries.

Sql Formatter Options Ddl Create

Linebreaks

  1. Before „(“ / After „(„

    • Before „(„: Adds a line break before the opening parenthesis in CREATE statements.
    • After „(„: Adds a line break after the opening parenthesis.
  2. Before „)“ / After „)“

    • Before „)“: Adds a line break before the closing parenthesis in CREATE statements.
    • After „)“: Adds a line break after the closing parenthesis.

Indentation

  1. Indent Cols in Brackets

    • Indents the column definitions inside parentheses for better alignment and readability in CREATE TABLE statements.
  2. Indent Bracket

    • Adds indentation to the opening and closing parentheses, ensuring they align correctly with the rest of the SQL structure.

My CREATE Keywords Getting Linebreaks

  • This section allows you to define specific CREATE keywords that should automatically receive line breaks in the formatted output.

 

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.

Sql Formatter Options Stored Proc Parms

Parms / Line

  1. 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.
  2. Before Comma / After Comma

    • Before Comma: Adds a line break before commas separating parameters.
    • After Comma: Adds a line break after commas separating parameters.
  3. Indent Parms

    • Indents all parameters to align them visually within the parameter list.

Parentheses

  1. Before „(“ / After „(„

    • Before „(„: Adds a line break before the opening parenthesis in the parameter list.
    • After „(„: Adds a line break after the opening parenthesis.
  2. 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

  1. 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.
  2. Control Comma Placement

    • Enable Before Comma or After Comma to manage line breaks around commas for separating parameters.
  3. Enable Indentation

    • Use Indent Parms to align all parameters neatly, making the code easier to scan and understand.
  4. 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.

By configuring these options, you can ensure that procedure and function parameter lists are consistently formatted, making them easier to read and maintain. For additional assistance, refer to the user manual or contact support.

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.

Sql Formatter Options Stored Proc Conditions

IF and THEN/ELSE Formatting

  1. IF

    • Adds a line break before or after the IF keyword to structure conditional statements.
  2. 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 the IF statement.
  3. 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.

Conditions

  1. 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.
  2. AND/OR

    • Adds a line break before logical operators (AND/OR) in conditional statements for clarity.
  3. Indent Conditions in Brackets

    • Indents conditions enclosed within parentheses to align them with the surrounding structure.
  4. Align Compare Operators (<, >, =, …)

    • Aligns comparison operators (e.g., <, >, =) to create a clean and visually consistent layout.

BEGIN/END

  1. Indent BEGIN … END
    • Indents the BEGIN and END blocks to reflect the nested structure of procedural SQL.
    • This ensures that all statements within the block are visually grouped.

How to Use These Settings

  1. Enable Line Breaks for Keywords

    • Use the checkboxes for IF, THEN, and ELSE to define where line breaks are added around these keywords.
  2. 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.
  3. 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.
  4. Align Operators

    • Enable Align Compare Operators (<, >, =, …) to create visually consistent conditional statements.
  5. 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.

Sql Formatter Options Stored Proc Variables

Available Options

  1. 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.
  2. 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.
  3. 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.

Sql Formatter Options Extract Generate

Extract SQL from Source Code

  1. 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;").
  2. 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.
  3. 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

  1. 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.
  2. 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.
  3. 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.
  4. 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.