SQL Scripting Best Practices | Details
Posted on 2020-04-22
About
WIP
I plan on copying or referring to this file for best practices. I admit I might break my own rules and if so, that's a bug!
Checklist
- Use the 80 column rule and strive for 70.
- End file with a newline.
- Keywords et al should use uppercase.
- delete-trailing-whitespace
- untabify
- Avoid trailing comments
- Prefer -- comments over comments
Example checks
theFile=path/to/file
grep -Iirn '^.\{71\}' ${theFile}
tail -c 1 ${theFile}
grep -Iirn '/\*\|\*/' ${theFile}
theFile=path/to/file
sqlformat \
\
--comma_first True\
--indent_columns \
--indent_width 4 \
--wrap_after 70 \
-k upper \
\
-o foo.sql \
\
${theFile}