SQL Style Tips - general

Hello, has anyone found any useful guides on formatting SQL queries?

I have read the one provided by DQ https://www.sqlstyle.guide/ but it does not discuss indentation beyond ‘the river’ between the keywords and rest of the code.

For example, I have seen in the DQ practice question answers that in CASE statements, the following WHEN clause is on a new line and indented two spaces to the right.

image

The reasons behind this have not been explained in the SQL Fundamentals course.

Can anyone help?

Thanks,
Levi

Hi @deeble.levi and welcome to the community!

It’s been a while since I used/studied SQL but I remember having similar thoughts/questions when I first started, like you. I wrote a little article about it here if you’d like to take a look.

Hi @mathmike314 ,

It’s nice to meet you!

Oh wow, that article is incredibly helpful. It’s like you were reading my mind! I will definitely have a read of the other guides you shared and develop a consistent style within my own code that makes sense to me.

Thanks so much :slight_smile:

1 Like

Nice to meet you too, @deeble.levi. Well, you know what they say about great minds :sunglasses: