SQL style guide – a consistent code guide ensuring legible and maintainable code
1–10 of 11 posts
Re: SQL style guide – a consistent code guide ensuring legible and maintainable code
#2This goes contrary to what I was taught : use singular form. When I model my databases I think in those terms : employee works for 1 to n company, company has 0 to n employee. Since it's a "many to many" relationship you need a third table (entity really) which you could call "working_with". The columns are id_employee and id_company.
This is the basis of the Merise method, but I don't think it's available in English. It makes modeling databases really easy.
Re: SQL style guide – a consistent code guide ensuring legible and maintainable code
#3"Use a collective name or, less ideally, a plural form. For example (in order of preference) staff and employees." This goes contrary to what I was taught : use singular form. When I model my databases I think in those terms : employee works for 1 to n company, company has 0 to n employee. Since it's a "many to many" relationship you need a third table (entity really) which you could call "working_with". The columns…
Re: SQL style guide – a consistent code guide ensuring legible and maintainable code
#4I hope Simon Holywell has never had to model a zoo in SQL. "Where are the rattlesnakes Simon - are they in the rhumba, crash or knot table?" [1]
[1] http://blog.writeathome.com/index.php/2013/03/improved-anima...
Re: SQL style guide – a consistent code guide ensuring legible and maintainable code
#5 select *
from asdf
where col1 = 5
or col2 = 6
I'll concede that the river is less pretty, but it's substantially easier to type, and SQL keywords are remarkably conducive to being tabbed around.EDIT: Perhaps hilariously, by preceding the code with two spaces, the stuff got out of alignment. I'm adding another two padding spaces to start. (I usually use a 4 space tab, but I can see how the river becomes a bit wide on 8.)
Re: SQL style guide – a consistent code guide ensuring legible and maintainable code
#6"Use a collective name or, less ideally, a plural form. For example (in order of preference) staff and employees." This goes contrary to what I was taught : use singular form. When I model my databases I think in those terms : employee works for 1 to n company, company has 0 to n employee. Since it's a "many to many" relationship you need a third table (entity really) which you could call "working_with". The columns…
- mapping is not intuitive for non-native English speakers (flora, really?!)
- manual table mapping needed for ORM systems
I'd prefer the singular, but ActiveRecord uses the plural, and I'd rather go along with the default, rather than fight and create friction for my team.
EDIT: looking closer, the style guide is great, but the naming conventions are atrocious. I'm reminded of what my Intro to CS TA told us: naming stuff is hard, so try to explain your code. If you have to explain what something is, the explanation should be the name (within reason)
Re: SQL style guide – a consistent code guide ensuring legible and maintainable code
#7"Use a collective name or, less ideally, a plural form. For example (in order of preference) staff and employees." I hope Simon Holywell has never had to model a zoo in SQL. "Where are the rattlesnakes Simon - are they in the rhumba, crash or knot table?" [1] [1] http://blog.writeathome.com/index.php/2013/03/improved-anima...
Re: SQL style guide – a consistent code guide ensuring legible and maintainable code
#8"Use a collective name or, less ideally, a plural form. For example (in order of preference) staff and employees." This goes contrary to what I was taught : use singular form. When I model my databases I think in those terms : employee works for 1 to n company, company has 0 to n employee. Since it's a "many to many" relationship you need a third table (entity really) which you could call "working_with". The columns…
I would suggest a different approach: Prefer either the plural or singular form, depending on which your ORM prefers. It may not be pretty from a purely stylistic perspective, but the collective forms have a few specific problems: - mapping is not intuitive for non-native English speakers (flora, really?!) - manual table mapping needed for ORM systems I'd prefer the singular, but ActiveRecord uses the plural, and I'd…
As for the non-English speakers finding the collective difficult; I can see that. I have not specifically considered their needs whilst compiling the guide. In the case of `flora` I am guessing you're thinking `plant`?
Re: SQL style guide – a consistent code guide ensuring legible and maintainable code
#9"Use a collective name or, less ideally, a plural form. For example (in order of preference) staff and employees." This goes contrary to what I was taught : use singular form. When I model my databases I think in those terms : employee works for 1 to n company, company has 0 to n employee. Since it's a "many to many" relationship you need a third table (entity really) which you could call "working_with". The columns…
Someone mentioned that tables can be considered like types - another interesting thought - in which case singular makes sense.
On the other hand it is a collection of something and therefore the collective term applies equally well.
Re: SQL style guide – a consistent code guide ensuring legible and maintainable code
#10Earlier quoted context omitted.
I would suggest a different approach: Prefer either the plural or singular form, depending on which your ORM prefers. It may not be pretty from a purely stylistic perspective, but the collective forms have a few specific problems: - mapping is not intuitive for non-native English speakers (flora, really?!) - manual table mapping needed for ORM systems I'd prefer the singular, but ActiveRecord uses the plural, and I'd…
When modelling data it should be the primary concern and not an ORM. Different applications will need access to the same information. ORMs are application specific and therefore should not determine how data is structured. As for the non-English speakers finding the collective difficult; I can see that. I have not specifically considered their needs whilst compiling the guide. In the case of `flora` I am guessing you…
Speaking from experience, you can't even expect native speakers to know all the collective forms. Worse, in some cases the collective form may cause confusion if the collective is the singular of a different table (players in a team, teams in a league, doing a fantasy football league app).
Using the plural, your schema would be player -> team -> league. Using your system, it would be team -> league -> sport. Good luck explaining that to a new hire.