Lecture 10 - SQL Best Practices
Lecture 10 - SQL Best Practices
Coding Standard/Convention
Correct:
Incorrect:
Correct:
Incorrect:
Correct:
EmployeeSalaryID INT
Incorrect:
EmployeesalaryID int
Correct:
Incorrect:
Do not use any special or language dependent characters to name objects. Constraints can
use the underscore character.
Correct:
Incorrect:
Correct:
Incorrect:
Correct:
Incorrect:
Correct:
1. Enhanced Efficiency
3. Minimal Complexity
4. Easy to Maintain
5. Bug Rectification
6. A Comprehensive Look
7. Cost-Efficient
SQL Comment
✓ Block comment:
SQL Comment
Naming conventions
❖ Names must begin with a letter and may not end with an
underscore.
Naming conventions
Format code
❖ Original query:
× SELECT * FROM Students;
❖ Improved query:
✓ SELECT Name, ClassName FROM Students;
❖ The HAVING clause is used to filter the rows after all the
rows are selected and it is used like a filter.
❖ Original query
❖ Improved query
❖ Improved query
❖ Improved query
❖ Improved query
❖ Improved query