SQL Best Practice

Some of the best practices that you should remember while writing an SQL query are as follows:

  • Comment your code using a hyphen ‘-’ for a single line and ‘/* … */’ for multiple lines of code.
  • Always use table aliases when your query involves more than one source table.
  • Assign simple and descriptive names to columns and tables.
  • Write SQL keywords in upper case and the names of columns, tables and variables in lower case.
  • Always use column names in the ‘order by’ clause instead of numbers.
  • Maintain the right indentation for different sections of a query.
  • Use new lines for different sections of a query.
  • Use a new line for each column name.
  • Use the SQL Formatter or the MySQL Workbench Beautification tool (Ctrl+B) to clean your code.

ODSC - Open Data Science Data & Society The Movie Database SQLRockstar Sequel Vanessa Query Coding Query Julia Query

Tech enthusiastic, life explorer, single, motivator, blogger, writer, software engineer