Use format tool (PoorSQL)
Upper Case keyword, DB and Tables
Use good alias
Think about the column order
Comment your code
anything else (e.g. ending semicolon ;, SORT BY, etc.)
Convert all lower cases
not perfect - 60% optimized
Set Max Width (chars) is 79
check Trailing Commas
check Break Join ON Sections
All other settings keep as is.
SQL keywords
Schema Name
Table Name
Column Datatype
Alias -> "shorter name"
always an alias when +1 table
short but relevant
one-word -> use first 3-4 letter
DIM.DIM_ARTICLE AS art
DIM.PRODUCT_ARTICLE_DATAMART
AS pad
snake case -> first letter from every word
Structure in a logical order left to right:
Primary key
Foreign key
Attributes
Metadata
internally: business logic from the lowest granularity and up
SELECT
store,
article,
country,
corporate brand,
department,
planning market,
product
...
SELECT store, country, planning market, corporate brand,
article, product, department, ...
This code is doing Y
Filtering on X due to Y
Casting X due to Y