SQL is utilized to recover information from database and overseeing information into the database. The DBMS forms the SQL ask for and recovers the fancied yield. SQL includes creating the database, modifying the database, deleting the database, retrieving the rows and column values. Client can compose SQL script to execute and SQL compiler consequently creates a method to get to database and convey the craved yield.
SQL Best Practices
Avoid Use Select * in a SQL statement query. It will retrieve all the column data that may not be wanted and will increase the query execution time.
For finding a null column use IS NULL instead of "=null"
UNION ALL can be used instead of UNION if sure that no duplicate row will not be retrieved.
Index is very useful for a table if it has less number of insert and update operations.
Must use all the column name in GROUP BY clause present in SELECT statement except the aggregate function in SELECT proclamation.
Try to use only aggregate functions in HAVING.
Examples
Describes a sample example for SQL program.
[c]
SELECT dept_num, avg(marks)FROM student_details
GROUP BY dept_num
HAVING dept_num IN ('D101', 'D103', 'D102') ;
[/c]
This is can be written in a better way like
[c]
SELECT dept_num, avg(marks) FROM student_details WHERE dept_num IN ('D101', 'D103', 'D102');
GROUP BY dept_num[/c]
In HAVING clause good to use aggregate functions.
Summary
Key Points
SQL Best Practices - Describes some sample examples related to the SQL Database.