Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Naming Database Tables: Is It Person, Peoples, Persons or People? (agilesql.club)
18 points by ed_elliott_asc on May 2, 2019 | hide | past | favorite | 22 comments


I don't think whether the names are plural or not actually matters. What matters is that a style is chosen and used consistently.


Consistency is king :)


The only problem with singular nouns for table names is that they occasionally conflict with SQL keywords. The canonical example of this is from the TPC-H benchmark which has tables named REGION, NATION, SUPPLIER, CUSTOMER, PART, PARTSUPP, LINEITEM ... AND ORDERS <- plural because ORDER is a SQL keyword.

I like the singular guidance for all the reasons given. I like the consistency guidance. But the real world sometimes gets in the way.


true but using [] fixes that, and they can be added by tooling


The thing that I get annoyed by is when the columns don't match the table names so something like:

create table people(person_id int)

This literally drives me to distraction and I want to throw my computer out of the window :)


According to my CS professor it's

  create table person(id int)
According to Rails it's

  create table people(id int)
Both agree on how to name the primary key. Person_id would be redundant.


I prefer person and person_id because when joining to to other tables it is easier (in my head) to join person_id to person_id than person_id to id


  select *
  from person
      join phone on person.id = phone.person


Have you tried creating an alias in your statement(s)? Using `AS` to make this explicit may further help. Just a suggestion.


yes but it is still an akwardness i prefer to avoid by using tablename_id like you'd have to do something like

"select id as tablename_id, * from table"

just doesn't feel quite right to me personally


how about person_id to person.id?


You might still need "person_id" for foreign keys no?


  select *
  from person p
      join phone ph on p.id = ph.person


One should just use the column name "id" then the table can be renamed if needed without having to rename the columns or perhaps the indexes. Although that's another debate altogether..


I work with ms sql server and use ssdt - with that we can rename columns and tables in the ide and ssdt generates a deployment script that renames the column and table and also all the references pointing to the column or table.


That is not drastic enough of an example. I can figure out that person is related to people as bad as it sounds.


I don't think there is a drastic example but i've probably worn down my backspace key a bit more than I should have :)


That's really valid I should have included that


The hardest thing in IT is naming things :D


it's a people table with person ids.


How do you name:

- an API endpoint

- an array

- a computer folder

- a paper folder


Not just api endpoints, what about URLs which are used by laypeople without English fluency?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: