Happy New Year to All of YOU!
Let us start year 2009 with word of wisdom from Albert Einstein.
I feel that you are justified in looking into the future with true assurance, because you have a mode of living in which we find the joy of life and the joy of work harmoniously combined. Added to this is the spirit of ambition which pervades your very being, and seems to make the day’s work like a happy child at play. – Albert Einstein
“May this new year all your dreams turn into reality and all your efforts into great achievements.”
Every new year we all make resolutions and some follow it and some forget as times goes by. I suggest that this year we all together follow SQL 5 best practices resolutions.They are very easy and very simple but if you follow them I promise that next year at this time you will be for sure in thanking yourself.
- Use JOIN syntax instead of using comma separate tables in FROM clause.
Correct Syntax :
SELECT *
FROM TableName T
INNER JOIN TableName2 T2 ON T.Col = T2.Col
Incorrect Syntax : SELECT * FROM TableName T, TableName2 T2 WHERE T.Col = T2.Col - Always alias table and use alias as prefix to column name.
Correct Syntax :
SELECT T.Col, T2.Col1
FROM TableName T
INNER JOIN TableName2 T2 ON T.Col = T2.Col
Incorrect Syntax : SELECT Col, Col1 FROM TableName T INNER JOIN TableName2 T2 ON T.Col = T2.Col - A table should contain at least one Primary Key and one Clustered Index.
- Make sure that views are not used much and table is directly used in queries.
- Take backup of system and attempt to restore it to make sure it can be done easily in time of emergency.
Reference : Pinal Dave (https://blog.sqlauthority.com)
2 Comments. Leave new
#4 – Make sure views are not used much and table is directly used in queries.
We are currently going through a process of using views. This resolution leads me to believe that this is not a sound decision.
Can you elaborate on this point please?
Thanks,
Kelley
What is this better
Use JOIN syntax instead of using comma separate tables in FROM clause.
Correct Syntax :
SELECT *
FROM TableName T
INNER JOIN TableName2 T2 ON T.Col = T2.Col
Incorrect Syntax : SELECT * FROM TableName T, TableName2 T2 WHERE T.Col = T2.Col