SQL style guide by Simon Holywell
sqlstyle.guide
SQL style guide by Simon Holywell
1–10 of 76 posts
Re: SQL style guide by Simon Holywell
#22018 (59 points, 16 comments) https://news.ycombinator.com/item?id=17924917
2016 (257 points, 147 comments) https://news.ycombinator.com/item?id=12671667
2015 (16 points, 10 comments) https://news.ycombinator.com/item?id=9941150
Re: SQL style guide by Simon Holywell
#3From this style guide, the aliases section would look like this in my style guide:
SELECT first_name
FROM staff
JOIN students
ON students.mentor_id = staff.staff_num;Re: SQL style guide by Simon Holywell
#4Re: SQL style guide by Simon Holywell
#5IMO, reading “SELECT employee.first_name” makes much more sense than “SELECT staff.first_name”.
Re: SQL style guide by Simon Holywell
#6I've stopped using aliases in the SQL I write and it's dramatically increased the clarify. From this style guide, the aliases section would look like this in my style guide: SELECT first_name FROM staff JOIN students ON students.mentor_id = staff.staff_num;
Re: SQL style guide by Simon Holywell
#7I’m probably alone in this, but I dislike naming tables in plural. IMO, reading “SELECT employee.first_name” makes much more sense than “SELECT staff.first_name”.
Re: SQL style guide by Simon Holywell
#8Re: SQL style guide by Simon Holywell
#9Not bad advice. The one about “where possible avoid simply using id as the primary identifier for the table” stood out to me. In the past with multiple ORMs (ya, ya, we all hate them) the default was to map to a column named id. Also when doing joins its cleaner to use the table_name.id or alias.id then table_name.table_name_id or alias.table_name_id or whatever else besides id is used. The best is when multiple peop…
I do agree it makes joins more verbose.
Re: SQL style guide by Simon Holywell
#10I’m probably alone in this, but I dislike naming tables in plural. IMO, reading “SELECT employee.first_name” makes much more sense than “SELECT staff.first_name”.