IKH

Best Practices – II

In the previous segment, you understood the importance of following best practices while writing queries in SQL. Now, let’s watch the next video to learn about some of the guidelines that you should follow while writing queries.

In this video, you learnt about some of the important best practices, which are as follows:

  • Comment your code by 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 a new line for each column name.
  • Use the SQL Formatter or the MySQL Workbench Beautification tool (Ctrl+B).

As Shreyas mentioned in the previous video, you can beautify your code by using either the MySQL Workbench Beautification tool or the SQL Formatter (or another similar online formatter). Now, let’s watch the next video to learn more about the SQL Formatter.

As you learnt in this video, the SQL Formatter is a handy online tool that enables you to customise the formatting of your code. Make sure you are comfortable using the tool and make it a practice to use it while writing a query.

In the next segment, you will learn the concept of indexing and also understand how it optimises query execution.

The link to the SQL Formatter is provided below.

Report an error