Skip to main content

Formatting Instructions

  1. Use consistent indentation (2 or 4 spaces) for nested clauses.
  2. Place each major SQL clause (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY) on a new line.
  3. Write SQL keywords in uppercase for clarity.
  4. Align columns, conditions, and JOIN clauses vertically when appropriate.
  5. Use aliases for all column names, table names, subqueries, and join tables with the AS keyword.
  6. Choose descriptive and meaningful aliases that accurately represent the data.
  7. List each column on a separate line in the SELECT clause when selecting multiple columns.
  8. Ensure proper spacing around operators and commas.
  9. Use table aliases for all table references to improve query readability.
  10. For database tenancy, replace all schema references with {{DATABASE_NAME}}.
To apply these guidelines to different SQL environments, refer to the sections below:
Guideline 1: Use Aliases for ReadabilityAlways use aliases for column names, table names, subqueries, and join tables using the AS keyword. Aliases improve readability and make queries more concise.Guideline 2: Enclose Identifiers in Double Quotes (")Always use double quotes for column, table, and subquery names to avoid conflicts with reserved keywords and case-sensitive identifiers.Guideline 3: Reference Tables with the Database NameAlways prefix tables with the database and schema name to ensure clarity, especially in multi-schema databases.**Example Use **Case
Guideline 1: Use Aliases for ReadabilityAlways use aliases for column names, table names, subqueries, and join tables using the AS keyword. Aliases improve readability and make queries more concise.Guideline 2: Enclose Identifiers in Double Quotes (")Always use double quotes for column names to avoid conflicts with reserved keywords and case-sensitive identifiers.Guideline 3: Reference Tables with the Database NameAlways prefix tables with the database and schema name to ensure clarity, especially in multi-schema databases.Example Use Case
Guideline 1: Use Aliases for ReadabilityAlways use aliases for column names, table names, subqueries, and join tables using the AS keyword. Aliases improve readability and make queries more concise.Guideline 2: Enclose Identifiers in Double Quotes (`)Always use backticks for column names to avoid conflicts with reserved keywords and case-sensitive identifiers.Guideline 3: Reference Tables with the Database NameAlways prefix tables with the database and schema name to ensure clarity, especially in multi-schema databases.
**Guideline 1: **Use clear and consistent formatting**Guideline 2: **Write precise queries**Guideline 3: **Utilize column aliasesExample Use Case
Guideline 1: Use Aliases for ReadabilityAlways use aliases for column names, table names, subqueries, and join tables using the AS keyword. Aliases improve readability and make queries more concise.Guideline 2: Enclose Identifiers in Double Quotes (")Always use double quotes for column, table, and subquery names to avoid conflicts with reserved keywords and case-sensitive identifiers.Guideline 3: Reference Tables with the Database NameAlways prefix tables with the database and schema name to ensure clarity, especially in multi-schema databases.Example Use Case
Guideline 1: Use proper syntax for MongoDB collections and fieldsWhen querying MongoDB with SQL, wrap collection names and field names in square brackets to avoid syntax errors.Guideline 2: Utilize projections to return only necessary dataThis improves query performance by limiting the amount of data transferred and processed.Guideline 3: Leverage indexing for frequently queried fieldsCreate indexes on commonly searched fields to significantly enhance query performance
Guideline 1: Use Aliases for column namesGuideline 2: Do not use schema names
**Guideline 1: **Use specific column names instead of SELECT *This reduces the amount of data processed and transferred, speeding up queries.**Guideline 2: **Utilize WHERE clauses to filter rows earlyThis reduces the number of rows processed in later stages of the query, improving performance.Guideline 3: Implement proper indexingCreate indexes on frequently queried columns to drastically improve query performance.
**Guideline 1: Use Clear and Consistent Aliases for Columns and Tables **Use descriptive and consistent aliases (with AS) for column and table names to improve readability and simplify column references.Guideline 2: Enclose Identifiers in BackticksUse backticks around column and table names, especially if they contain spaces, special characters, or case sensitivity to avoid parsing errors.
Guideline 1: Use Aliases for ReadabilityAlways use aliases for column names, table names, subqueries, and join tables using the AS keyword. Aliases improve readability and make queries more concise.Guideline 2: Enclose Identifiers in Double Quotes (")Always use double quotes for column, table, and subquery names to avoid conflicts with reserved keywords and case-sensitive identifiers.Guideline 3: Reference Tables with the Database NameAlways prefix tables with the database and schema name to ensure clarity, especially in multi-schema databases.Example Use Case
Guideline 1: Use Aliases for ReadabilityAlways use aliases for column names, table names, subqueries, and join tables using the AS keyword. Aliases improve readability and make queries more concise.Guideline 2: Enclose Identifiers in Double Quotes (")Always use double quotes for column, table, and subquery names to avoid conflicts with reserved keywords and case-sensitive identifiers.Guideline 3: Reference Tables with the Database NameAlways prefix tables with the database and schema name to ensure clarity, especially in multi-schema databases.Example Use Case
Guideline 1: Use Aliases for ReadabilityAlways use aliases for column names, table names, subqueries, and join tables using the AS keyword. Aliases improve readability and make queries more concise.Guideline 2: Enclose Identifiers in Double Quotes (")Always use double quotes for column, table, and subquery names to avoid conflicts with reserved keywords and case-sensitive identifiers.Guideline 3: Reference Tables with the Database NameAlways prefix tables with the database and schema name to ensure clarity, especially in multi-schema databases.Example Use Case
Guideline 1: Use Aliases for ReadabilityAlways use aliases for column names, table names, subqueries, and join tables using the AS keyword. Aliases improve readability and make queries more concise.Guideline 2: Enclose Identifiers in Backticks (`)Database names, table names, and column names should be enclosed in backticks (`).Guideline 3: Reference Tables with the Database NameAlways prefix tables with the database and schema name to ensure clarity, especially in multi-schema databases.
**Guideline 1: Use Clear and Consistent Aliases for Columns and Tables **Use descriptive and consistent aliases (with AS) for column and table names to improve readability and simplify column references.Guideline 2: Enclose Identifiers in BackticksUse backticks around column and table names, especially if they contain spaces, special characters, or case sensitivity to avoid parsing errors.
To automatically correct and format your SQL query, click the “Format Query with AI” icon. This converts your SQL into DataBrain’s preferred format, ensuring proper syntax, clear indentation, and better readability.
Format Query with AI