MySQL how to beauty SQL code?
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?
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?
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:-
SELECTÂ
id
,fullname
,dob
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
FROM EMPLOYEE EMP
Instead:-
SELECT emp_name
FROM EMPLOYEE A
8. Do not use reserve SQL words for database names, table names and column names as it can create ambiguity.