MySQL how to beauty SQL code?

Asked By 60 points N/A Posted on -

I have got and idea for MySQL how to beautify SQL code and I am planning to use SQLinForm software for that. Does anybody use it for DB2 and which are results?

Answered By 0 points N/A #145856

MySQL how to beauty SQL code?


Hi Jamin,

Hope you are doing well. Beautifying SQL code is not easy as it is a descriptive language. However by following certain guidelines or coding standards of SQL one can make it more readable, hence beautiful. 

1. Try to write reserved words, Table and database names in Capitals

2. Try not to use SELECT *, instead clearly define all the columns you want to select.

3. While writing columns in SELECT statement, try to enter single column in a line proceeding with commas. For example try:-





instead select id, fullname,dob

4. Try using search on Primary_keys, like use PKs in WHERE while doing SELECT, UPDATE OR DELETE.

5. Try to use following convention when defining a PK. PK_TableName

6 Try to use following convention while defining a FK. FK_tableName_1_tableName_2. For example FK_DEPARTMENT_EMPLOYEE

7. Try giving meaningful aliases for table names and column names. Try:-

SELECT emp_name



SELECT emp_name


8. Do not use reserve SQL words for database names, table names and column names as it can create ambiguity.

Login/Register to Answer

Related Questions