<commit_before>---
title: formatting
authors: emesika
wiki_title: OVirt-DB-Issues/formatting
wiki_revision_count: 29
wiki_last_updated: 2015-11-16
---

# formatting

The following SQL formatting rules apply to code written as views/SP/upgrade scripts under the dbscripts folder:

Please note that each example demonstrates ONLY the specific rule and not the entire formatting for simplicity.

Example that appears with red are wrong

Example that appears with blue are right

## Indentation

All indentations should use 4 spaces no TABs are allowed

## Capitalization

Keyword: UPPER
 SELECT Data type: lower
 varchar(32) Table name : lower
 users Column name : lower
 user_name Function name : InitCap for SP, lower for general functions that also must start with fn_db_
 InsertAuditLog

       fn_db_add_column

Column alias: lower
 dept AS department Variable : lower, starts with v_
 v_user Constraint: lower

       fk_user_user_sessions

## Comma option

Always after item

select a
,b
,c
 from T;

select
a,
b,
c
 from T;

## AND/OR

Always in the end of line

a>1
and b<10

a>1 and
b<10

## Operators

Always surround operators with one space

       wrong:
        WHERE
            a+b=c
        rght:
        WHERE
            a + b = c

## Select Query

Column list : in a new line
column list style : stacked
INTO clause : in a new line
FROM clause : in a new line<commit_msg>Operators<commit_after>---
title: formatting
authors: emesika
wiki_title: OVirt-DB-Issues/formatting
wiki_revision_count: 29
wiki_last_updated: 2015-11-16
---

# formatting

The following SQL formatting rules apply to code written as views/SP/upgrade scripts under the dbscripts folder:

Please note that each example demonstrates ONLY the specific rule and not the entire formatting for simplicity.

Example that appears with red are wrong

Example that appears with blue are right

## Indentation

All indentations should use 4 spaces no TABs are allowed

## Capitalization

Keyword: UPPER
 SELECT Data type: lower
 varchar(32) Table name : lower
 users Column name : lower
 user_name Function name : InitCap for SP, lower for general functions that also must start with fn_db_
 InsertAuditLog

       fn_db_add_column

Column alias: lower
 dept AS department Variable : lower, starts with v_
 v_user Constraint: lower

       fk_user_user_sessions

## Comma option

Always after item

select a
,b
,c
 from T;

select
a,
b,
c
 from T;

## AND/OR

Always in the end of line

a>1
and b<10

a>1 and
b<10

## Operators

Always surround operators with one space

a+b=c

a + b = c

## Select Query

Column list : in a new line
column list style : stacked
INTO clause : in a new line
FROM clause : in a new line
{'fraction_non_alphanumeric': 0.05046382189239332, 'fraction_numerical': 0.014100185528756958, 'mean_word_length': 3.5928449744463373, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5268432', 'n_tokens_mistral': 890, 'n_tokens_neox': 821, 'n_words': 369}