- Use upper case for all SQL keywords
- SELECT, INSERT, UPDATE, WHERE, AND, OR, LIKE, etc.
- Indent code to improve readability
- Comment code blocks that are not easily understandable
- Use single-line comment markers(–)
- Reserve multi-line comments (/*.. ..*/) for blocking out sections of code
- Use single quote characters to delimit strings.
- Nest single quotes to express a single quote or apostrophe within a string
- For example, SET @sExample = ‘SQL”s Authority’
- Use parentheses to increase readability
WHERE (color=’red’ AND (size = 1 OR size = 2))
- Use BEGIN..END blocks only when multiple statements are present within a conditional code segment.
- Use one blank line to separate code sections.
- Use spaces so that expressions read like sentences.
- Format JOIN operations using indents
- Also, use ANSI Joins instead of old style joins
- Place SET statements before any executing code in the procedure.
|