When it comes to reading code no body will like to read a wall of text specially in programming. Some of the best practices to make query code readable, as well as easier to understand, is to follow clean formatting rules throughout your SQL query. Some good practices to write a good query is:
- Use comments to describe what SQL does. If you’re modifying existing SQL, add the author’s name, the date, describe the modifications, and avoid questions. Don’t overdo it and comment on the obvious
- Put each major SQL statement on a new line
- Use CamelCase capitalization and do not separate name parts with underscores: TableName, instead of Table_name, or use lower case and underscores to separate name parts: table_name
- Set standard abbreviations for frequently used objects, such as tbl for tables, or sp for stored procedures
- Use single quotation for characters, strings, binary and Unicode –
- Use indenting to align wrapped long lines
- Use parentheses in complex mathematical expressions
It is also important to use line breaks to improve readability, as well as separating lines of codes that execute certain tasks as different code blocks.
sources:
http://solutioncenter.apexsql.com/sql-formatting-standards-capitalization-indentation-comments-parenthesis/
- Use comments to describe what SQL does. If you’re modifying existing SQL, add the author’s name, the date, describe the modifications, and avoid questions. Don’t overdo it and comment on the obvious
- Put each major SQL statement on a new line
- Use CamelCase capitalization and do not separate name parts with underscores: TableName, instead of Table_name, or use lower case and underscores to separate name parts: table_name
- Set standard abbreviations for frequently used objects, such as tbl for tables, or sp for stored procedures
- Use single quotation for characters, strings, binary and Unicode –
- Use indenting to align wrapped long lines
- Use parentheses in complex mathematical expressions
It is also important to use line breaks to improve readability, as well as separating lines of codes that execute certain tasks as different code blocks.
sources:
http://solutioncenter.apexsql.com/sql-formatting-standards-capitalization-indentation-comments-parenthesis/
Comments
Post a Comment