From the beginning of time, January 1st, 1900, people have asked, "Should I use commas at the end of column names, or at the start?
-- English Majors
SELECT
FirstName,
MiddleName,
LastName,
EmployeeNo,
SeniorityDate,
JobTitle,
Active
FROM Employees
WHERE active=1
ORDER BY LastnName,FirstName;
-- Programmers
SELECT
FirstName
,MiddleName
,LastName
,EmployeeNo
,SeniorityDate
,JobTitle
,Active
FROM Employees
WHERE active=1
ORDER BY LastnName,FirstName;
The latter has a few advantages. You can comment out a column while writing it without having to edit near the actual column name, so it's faster to add columns in the middle. You can add columns to the end of it very easily by just preceding them with a comma. The English major method would mean you have to add a new comma to the penultimate column each time you add a new one to the end. Commenting is likewise simpler with the comma-first method. I think the final word in this debate should be a mournful shrug. Do what you prefer as long as it's not an unreadable mix. There is also the school of thought of stacking columns horizontally when you have an unworldly number of them like...
select
FirstName,MiddleName,LastName,EmployeeNo,SeniorityDate, --5
JobTitle,Active --7
FROM Employees
WHERE active=1
ORDER BY LastnName,FirstName;
etc.
I do think adding line numbering will help preserve the already shaky sanity of those coming later to debug. Just every 5 lines or so should be enough. And as far as the comments go - I'd kind of prefer to see them on their own lines.
select
FirstName,
MiddleName,
LastName,
EmployeeNo,
SeniorityDate, --5
-- 10/1/2021 Kim F. This is the new WorkdayTitles, not the ones from ToFu
JobTitle,
Active,
ManagerEmpployeeNo,
CostCenter,
SecurityGroup --10
FROM Employees
WHERE active=1
ORDER BY LastnName,FirstName;
etc.
I know comma-first has it's advantages, but if you ever need to present the list of fields to...normies outside of the great Database Kingdoms, comma after will convince them you are mostly human.
Let us speak of this no more.
No comments:
Post a Comment