Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database table names: Plural or Singular [closed]

What is the most common naming convention for SQL Database tables? Was it historically one way and now it's better to do another way? What are the most common practices now?

like image 251
John Egbert Avatar asked Sep 11 '10 00:09

John Egbert


People also ask

Should database table names be singular or plural?

So Which Should I Use: Singular or Plural? The correct answer is that there is no right or wrong when naming database tables — just be consistent from the start. The only wrong answer with database table names is to use a combination of plural and singular.

Is tables singular or plural?

The plural form of table; more than one (kind of) table.

Should entity names be plural?

The defined standard is to go for non-plural because in a table we are storing a set of an entity and we name the table as the entity so if we want to store one or more people in a single entity or table, we store it or them in the “Person” table.

Is database plural or singular?

The plural form of database is databases. Find more words!


2 Answers

I always use plural for table names and singular for column names. Not that there's any real technical reason for it, that's just what I prefer.

Doesn't much matter, so long as you are consistent.

I.e.

+========+       +==========+
| Posts  |       | Users    |
+--------+       +----------+
| idPost |   |-> | idUser   |
| Poster | <-|   | Name     |
+========+       +==========+

My reasoning for this is what happens when you write the actual query:

SELECT idPost, Name FROM Posts
INNER JOIN Users ON Poster = idUser

If you use singular, it looks like you're selecting from a post, rather than from the set of all posts, and joining to a single user, instead of all users.

like image 138
Billy ONeal Avatar answered Sep 30 '22 18:09

Billy ONeal


Nope - singular for me. It's the "USER" table.

like image 27
duffymo Avatar answered Sep 30 '22 18:09

duffymo