If a query is parsed and executed without any errors. it is means it met the basic standards of that language.
As far as where to put commas and how to indent your code its all down to personal preferences.
Yes there are some best practices defined by the people which are again considered by most of the people as a "Best Practice" but not all.
There are some best practices on which most of the people will agree but not all.
- Things are clever, but not too clever (KISS / Keep it simple
stupid)
- A Parsed query is not the best query, try writing
Covering Queries when ever possible.
- Use atleast two-part name for your object like [Schema].[TableName]
- Object
(Tables, Columns, Stored Procedures) variables and functions are well
named and make sense without having to think too much.
- You come back to it after a weekend off, and you can jump straight in
- Things that will be reused are reusable
- Code that
looks cleaner. will be easier to debug and modify at later stage.
- "Comments" using comments to explain what a code snippet does,
so if you come back to it after a month of so you will know by just
reading the comments what the code does rather then actually going
through the code itself.
- Use CAPITALS for key words like "
SELECT, FROM , WHERE " --<--
Keeping all these things in mind for above query I would write it something like this.
SELECT A.NAME
,A.SURNAME
,A.ADDRESS
FROM PERSON A
Coming back to the "Important Question" Leading Comma or Trailing Comma?
I personally find it easier to have leading commas in my code, as it makes easier for me to find where the the next column starts from , or to find the missing commas.
for example in the following query my answer to one of the question on stack over flow
SELECT radius
, Diameter
, CASE WHEN POWER( @p1 - x, 2) + POWER( @p2 - y, 2) <= POWER(radius, 2)
THEN 'Inside The Circle'
WHEN POWER( @p1 - x, 2) + POWER( @p2 - y, 2) > POWER(radius, 2)
THEN 'Outside the Circle' END [Inside/Outside]
FROM @t
The leading comma makes it so much easier to find a missing comma if I had one and to tell exactly how many column there are this this SELECT query.
Some Useful Link
Aaron Bertrand - Best Practices for Stored Procedures
Richard Espinoza SQL Server Concepts and Best Practices to Build Transact SQL Stored Procedures
pinaldave SQL SERVER – Bad Practice of Using Keywords as an Object Name – Avoid Using Keywords as an Object