I asked on Twitter about naming database tables. It goes without saying that Twitter polls are extremely scientific and a trustworthy tool for decision making.
[Poll] Are database table names supposed to be singular or plural?
— Dave Rupert (@davatron5000) March 10, 2020
I fall firmly into the plural camp, but the other day I was setting up a many-to-many
relationship in Hasura and was struggling with the documentation, even though I’ve made plenty of join
tables in the past. After leaving work, still thinking about it, it dawned on me that all their documentation had singular table names. I couldn’t believe it. “Surely, this is illegal?” I thought.
Then I started checking my own assumptions. It’s not likely, but maybe I am the one who’s wrong here…
I’m fairly certain that I picked this behavior up from using Rails and CakePHP from forever ago. Those frameworks and their conventions enforce plural table names. Somewhere along the way I convinced myself that this is the “correct” way to do it. It makes sense that a table of multiple Article
objects would be called articles
. It even reads well if you look at the SQL…
SELECT * FROM articles WHERE...
If you work with databases long enough you hit some edges of this dogma. Mass nouns like “evidence” or “research” don’t pluralize well and chip away at your perfect cathedral. Singular table names have an advantage here for sure.
Taking it a step further, Dhimas Widrayato makes a great observation that entire premise of my question is rather Anglo-centric…
In my language, plural words are just the singular version writen twice with hypen in between.
— Dhimas Widrayato (@dhimasbu) March 11, 2020
So when creating database table in my language, I always use singular. https://t.co/sCdRjvaEbj
Languages like Japanese, Malaysian, Javanese, and Indonesian repeat the noun to make it plural. For Dhimas and millions of others, repeating a noun for a database table name would be a superficial improvement…
…and so is maybe an s
…
…or es
…
…or changing us
to i
…
…or suffixing mass nouns with _items
.
Let’s be honest, English is a hot mess.
I don’t know if I’m converted to the singular camp, but this whole episode did challenge my preconceived notions. That’s fun. For this project, I think I’m going to try singular and see if I hate it. It probably will matter 1% in the long run.