frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Use singular nouns for database table names

https://www.teamten.com/lawrence/programming/use-singular-nouns-for-database-table-names.html
43•Bogdanp•3d ago

Comments

chasil•6h ago
SQLite has specific naming advice:

"For most SQL code, your safest bet is to never use any English language word as the name of a user-defined object...

"SQLite adds new keywords from time to time when it takes on new features. So to prevent your code from being broken by future enhancements, you should normally quote any identifier that is an English language word, even if you do not have to."

https://sqlite.org/lang_keywords.html

hvenev•6h ago
English also changes, so the only way to be safe is to quote all identifiers.
01HNNWZ0MV43FF•6h ago
I'll just stop upgrading SQLite if they ever add "rizz" as a keyword
phoyd•5h ago
I want to drop here the not very well known fact, that the SQL Standard grammar distinguishes between "SQL language identifier" and "regular identifier". According to the rules, a SQL language identifier can not end with an underscore (copied from ISO/IEC 9075-2:1999 "5.4 Names and identifiers":

<SQL language identifier> ::=<SQL language identifier start> [ { <underscore> | <SQL language identifier part> }... ]

<SQL language identifier start> ::= <simple Latin letter> <SQL language identifier part> ::= <simple Latin letter> | <digit>

So, using names with trailing underscore should always be safe.

isoprophlex•5h ago
French table and column names, here I come! La vache query!
metadat•6h ago
Does this qualify as bike shedding? What is the business impact either way? If someone prefers one or the other, so what!

All arguments seem pretty frail, always reduced to some form of "well this way makes it easier for ME to reason about!". I used to have opinions on this crap, and nowadays I've got way bigger fish to fry than worrying about table name plurality. As long as it's human-legible and consistent, who cares?

000ooo000•5h ago
>As long as it's [..] consistent, who cares?

That's what the article is about..

aakkaakk•5h ago
+1000

Use whatever convention (per app/db/team), as long as it is consistent. Developers who use mixed singular and plural in the same db should be fired (into the sun).

orphea•4h ago
It is clearly not, and that's the whole reason people have an issue with it.

The only mention of the word "consistency" was used to support the plural approach.

leoff•6h ago
Seriously? I don't care what you call your tables, as long as it's consistent and it's nothing egregious.
Joel_Mckay•4h ago
Sure, unless most the team is international, and the referenced "quote" was actually meant to function as "quota"... you just haven't earned your grey beard till you spent days chasing down a developer to explain their code.

Nice guy, but a conditional recursively defined polymorphic class on a transaction server should be a crime. lol =3

danbruc•6h ago
1. Strictly speaking, we’re not naming a table, we’re naming a relation.

And a relation is a set, hence plural.

2. It reads well everywhere else in the SQL query:

   SELECT Employee.Name
        , Manager.Name
     FROM Users AS Employee
        , Users AS Manager
    WHERE Employee.ManagerID = Manager.ID
      AND Employee.DateOfBirth IS NULL;
3. The name of the class you’ll store the data into is singular (User). You therefore have a mismatch, and in ORMs (e.g., Rails) they often automatically pluralize, with the predictable result of seeing tables with names like addresss.

The class User represents a single row, not the entire table, hence singular. If the O/R mapper or some other tooling has issues with singular and plural, then I agree, it might not be worth fighting the tools.

4. Some relations are already plural. Say you have a class called UserFacts that store miscellaneous information about a user, like age and favorite color. What will you call the database table?

I think having the table and the class name both in plural would be fine. That also seems rare enough in practice that I would not let this dictate the decision. In the given example I would also tend to record the user facts as a list of them. A user fact is a key value pair associated with an user, the keys living in their own table. Having the keys implicit as column names will also make some queries unnecessarily complicated and as the number of facts grows, the table will become increasingly wide.

Also sometimes we have singular names for collections of things, then it is fine to have a singular table name, you can name your Trees table Forrest if that makes sense in the domain.

dan-robertson•5h ago
A relation is a set in the same way that a function is a set. I don’t think that’s a useful fact when thinking about naming.
DougBTX•5h ago
> they often automatically pluralize, with the predictable result of seeing tables with names like addresss.

This is a very poor example, that case is literally in their unit tests file:

https://github.com/rails/rails/blob/b0c813bc7b61c71dd21ee3a6...

That test has been there over 18 years!

gorgoiler•4h ago
Are you advocating for using “select … from plural as singular” in all schema and queries?

  select sum(cat.length)
  from cats as cat
That’s an interesting approach I haven’t seen before.

(For me, I’m very much a singular it’s-a-datatype-not-a-collection person, but selecting from cat has always felt a bit awkward with that pattern.)

danbruc•4h ago
I think that is the correct way to do it, you iterate over all the cats picking one cat at a time and it becomes quite obvious when you join a table to itself forcing you to do this. I am not writing that many SQL queries and I am certainly too lazy to always do that, especially if I am writing not too complicated ad hoc queries, but if I want the code to be as good as I can make it, then I always do this. Sure, it makes things a bit more verbose but you can also make the query more readable by picking a descriptive alias, FROM Users AS Manager, FROM Users AS NewEmployee, and so on.
orphea•4h ago
Whether you alias your plural tables to singular nouns would probably be one of the very last things I would check out if I would need to assess your code.
danbruc•3h ago
And you should not but I think it is still useful. You will probably not even become consciously aware of the difference but Cat.Name will be ever so slightly easier to read than Cats.Name and maybe that difference in cognitive load is what makes you spot some issue that you would have missed if your brain got repeatedly slightly tripped up by incorrect grammatical numbers.
Glyptodon•6h ago
I don't like plural table names as a convention, but not enough to not use Rails or change its default behaviors.

For me, it's in the same category as preferring generated primary keys were named <table-name>_id over just "id" - you may have a preference, but it's not got that much big picture importance.

ambentzen•4h ago
If you have self-referential columns you are going to have to name them something else, like `parent_id` and tell your model code about the discrepancy.
shrikant•5h ago
Funnily enough, the blog post itself has a counterexample in their singular noun example: the table^Wrelation name is `user` which is highlighted by the syntax highlighter as being a keyword. I'd wager the same thing would happen for a table named, say, `transaction`.

Some DB engines won't let you use a keyword as identifiers for anything unless it's quoted, and then you either have to quote everything, or end up in a weird situation where some things are quoted and some aren't.

veltas•5h ago
I agree with the article on the basis it's easier to not bother trying to use a convention of plural names as there's a lot of time-wasting edge cases, and generally it's less weird seeing no plural than seeing a plural in the middle of an expression where it doesn't work.
presentation•5h ago
Sounds like bike shedding to me
jaapz•3h ago
Naming things is one of the hardest things in software engineering
arnaudsm•5h ago
My other favorite best practice with SQL is to have unique ID column names, so you never mix up IDs, and can use JOIN with the USING syntax:

  SELECT *
  FROM customer
  JOIN order USING (customer_id)
jiggawatts•5h ago
My reason for doing this is that there can be multiple foreign key columns pointing at the same table, each with a distinct purpose and name.

The general case is a named key.

vbezhenar•4h ago
I've never heard of `using` syntax. And now you might make me reconsider my identifier naming usage :) It certainly makes sense.
5123121•4h ago
The downside of this is GORM ( or new developer ) often just default to "id". Fighting against it will take away bits of your attention and effort.
arnaudsm•3h ago
Yep, it's unfortunately the industry standard, but in my career I've seen it lead to mixing up ids and painful debugging.
cynicalsecurity•5h ago
No.
adrianmsmith•5h ago
Having table names plural e.g. "customers" and object names in your programming language e.g. "customer" is one extra piece of complexity that's not necessary.

For example we have a table "customer_data" at work and in our generated ORM code it's called "customer_datum".

The open-source singularization library is doing its job, but it sure made it difficult for me to global-search for that object name when I joined the company and didn't know the object was called that.

5123121•4h ago
data is basically the singular word at this point in English language history :). "Datum" now remains as a fun quiz for the people who don't know.
adrianmsmith•5h ago
Join tables are a bit more difficult if you pluralize tables. For example at work we have table names like:

    customers
    customer_attributes
    customers_labels
On one side you want to be consistent with the "customers" table you're joining to. On the other hand it reads weirdly to have an extra "s" in the middle of the table name.

After you've got three or so words in a table name it really becomes inconsistent and you can't really guess what they're called when writing code.

There are solutions of course: whether to use the "s" on join tables could be a policy documented somewhere and everyone, including new employees, could be made aware of it. But it's a problem you don't have if you use singular table names.

FearNotDaniel•5h ago
This is the tabs vs spaces of SQL. Pick one and stick with it. If you join a project that has already chosen the “other” option that is not your favourite, just grow up and deal with it. Once decided, try to apply it consistently, unlike the final example given here which really ought to be “UserFactsCollection”, or List or Bag or whatever singular object they are actually saving per table row… and if you absolutely must write a blog post like this, don’t forget to preface the title with “I prefer to…”
c048•4h ago
I agree.

It is better to be consistent but wrong, than inconsistent but correct.

Consistent and correct might seem ideal, but merely the fact that what is 'correct' is in the eye of the beholder most of the time, making it basically unobtainable.

But being consistent is at least something that is far less subjective.

stcg•4h ago
I don't see consistent and correct as separate. Consistent is correct, and correct is consistent.
dwattttt•4h ago
Be sure to be consistent with each of the edge cases in order to be correct!
out_of_protocol•2h ago
> than inconsistent but correct.

than inconsistent but sometimes correct.

bob1029•4h ago
> which really ought to be “UserFactsCollection”, or List or Bag or whatever singular object they are actually saving per table row

I try to avoid putting nouns on things when they could otherwise be inferred from their context of use. In this case we know it's a table. The possibility of multiple items being included is implied.

Singular/plural debate is driving us to name stuff in weird ways. This is why you should just go with the flow. Consider what a non technical person somewhere else in the business might call it. Aligning with this language has tremendous benefits. Trying to force purity into a natural language and communications context is how we make type systems and schemas that are indecipherable to the business.

camgunz•5h ago
Strong disagree; there are multiple "things" in the "things" table. Also lead with your strongest argument, also `UserInfo` works, also it's probably not a good table (why isn't it just on `User`, why isn't it a many-to-many of user IDs to fact IDs w/ a value, etc. etc. etc.)
vbezhenar•5h ago
Not really related, but I hate that postgres have keyword `user` which makes it cumbersome to name table like that (you technically can do it, but you would need to quote it everywhere). This table is present in 99% projects, so it's PITA. I'm usually using "account" table because of that, but "user" feels more natural.
adrianmsmith•5h ago
The database vendors themselves don't seem to be consistent on this issue.

* PostgreSQL system table names are singular e.g. "pg_class"

* Oracle system tables are plural e.g. "ALL_TABLES"

* MySQL is also plural e.g. "schemata".

mediumsmart•4h ago
Good point. I am going to make a local form that will check a name I want to use for being a poor choice in rails.
vbezhenar•4h ago
Also related:

I skimmed classic Codd paper "A relational model of data for large shared data banks" which gave birth to RDMS.

Codd uses singular nouns for example relation names: PART, PROJECT, COMMIT, supply, component, employee, jobhistory, salaryhistory. The only exception is "children" relation.

So that's one small argument in favour of singular approach :)

huksley•4h ago
user is a resevered word in Postgres so it will be actually

> select * from "user"

which is ugly

rejschaap•4h ago
I like singular, most pick plural

I like tabs, most pick spaces

I like mercurial, most pick git

But no one’s taking my vim!

Mistral AI raises 1.7B€, enters strategic partnership with ASML

https://mistral.ai/news/mistral-ai-raises-1-7-b-to-accelerate-technological-progress-with-ai
449•TechTechTech•7h ago•265 comments

A clickable visual guide to the Rust type system

https://rustcurious.com/elements/
113•stmw•3d ago•11 comments

You too can run malware from NPM (I mean without consequences)

https://github.com/naugtur/running-qix-malware
66•naugtur•3h ago•47 comments

Hallucination Risk Calculator

https://github.com/leochlon/hallbayes
32•jadelcastillo•2h ago•8 comments

DuckDB NPM packages 1.3.3 and 1.29.2 compromised with malware

https://github.com/duckdb/duckdb-node/security/advisories/GHSA-w62p-hx95-gf2c
135•tosh•3h ago•83 comments

How can England possibly be running out of water?

https://www.theguardian.com/news/ng-interactive/2025/aug/17/how-can-england-possibly-be-running-o...
186•xrayarx•2d ago•281 comments

Weaponizing Ads: How Google and Facebook Ads Are Used to Wage Propaganda Wars

https://medium.com/@eslam.elsewedy/weaponizing-ads-how-governments-use-google-ads-and-facebook-ad...
38•bhouston•57m ago•17 comments

Signal Secure Backups

https://signal.org/blog/introducing-secure-backups/
891•keyboardJones•20h ago•394 comments

Nango (YC W23) Is Hiring a Staff Back End Engineer (Remote)

https://jobs.ashbyhq.com/Nango/3467f495-c833-4dcc-b119-cf43b7b93f84
1•bastienbeurier•1h ago

Anscombe's Quartet

https://en.wikipedia.org/wiki/Anscombe%27s_quartet
22•gidellav•1d ago•8 comments

Liquid Glass in the Browser: Refraction with CSS and SVG

https://kube.io/blog/liquid-glass-css-svg/
377•Sateeshm•15h ago•96 comments

iPhone dumbphone

https://stopa.io/post/297
536•joshmanders•19h ago•316 comments

Strong Eventual Consistency – The Big Idea Behind CRDTs

https://lewiscampbell.tech/blog/250908.html
86•tempodox•8h ago•35 comments

NPM debug and chalk packages compromised

https://www.aikido.dev/blog/npm-debug-and-chalk-packages-compromised
1236•universesquid•21h ago•662 comments

Experimenting with Local LLMs on macOS

https://blog.6nok.org/experimenting-with-local-llms-on-macos/
342•frontsideair•22h ago•226 comments

Deluxe Paint on the Commodore Amiga

https://stonetools.ghost.io/deluxepaint-amiga/
52•doener•3d ago•13 comments

Microsoft doubles down on small modular reactors and fusion energy

https://www.techradar.com/pro/microsoft-joins-world-nuclear-association-as-it-doubles-down-on-sma...
149•mikece•18h ago•261 comments

The elegance of movement in Silksong

https://theahura.substack.com/p/the-elegance-of-movement-in-silksong
137•theahura•16h ago•209 comments

Alterego: Thought to Text

https://www.alterego.io/
159•oldfuture•16h ago•106 comments

Contracts for C

https://gustedt.wordpress.com/2025/03/10/contracts-for-c/
90•joexbayer•4d ago•69 comments

X Design Notes: Unifying OCaml Modules and Values

https://blog.polybdenum.com/2025/08/19/x-design-notes-unifying-ocaml-modules-and-values.html
13•todsacerdoti•3d ago•0 comments

Is OOXML Artifically Complex?

https://hsu.cy/2025/09/is-ooxml-artificially-complex/
118•firexcy•3d ago•113 comments

No adblocker detected

https://maurycyz.com/misc/ads/
508•LorenDB•12h ago•264 comments

Majority in EU's biggest states believes bloc 'sold out' in US tariff deal

https://www.theguardian.com/world/2025/sep/09/majority-in-eu-biggest-states-believes-bloc-sold-ou...
12•belter•2h ago•2 comments

Clankers Die on Christmas

https://remyhax.xyz/posts/clankers-die-on-christmas/
240•jerrythegerbil•22h ago•196 comments

Will Amazon S3 Vectors kill vector databases or save them?

https://zilliz.com/blog/will-amazon-s3-vectors-kill-vector-databases-or-save-them
246•Fendy•21h ago•111 comments

Seedship – Text-Based Game

https://philome.la/johnayliff/seedship/play/index.html
109•ntnbr•3d ago•42 comments

Show HN: Attempt – A CLI for retrying fallible commands

https://github.com/MaxBondABE/attempt
58•maxbond•11h ago•15 comments

The key points of "Working Effectively with Legacy Code"

https://understandlegacycode.com/blog/key-points-of-working-effectively-with-legacy-code/
157•lordleft•3d ago•62 comments

AMD claims Arm ISA doesn't offer efficiency advantage over x86

https://www.techpowerup.com/340779/amd-claims-arm-isa-doesnt-offer-efficiency-advantage-over-x86
197•ksec•22h ago•365 comments