开发者

Database table names: Plural or Singular [closed]

开发者 https://www.devze.com 2023-01-15 22:53 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, argument开发者_如何学JAVAs, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 12 years ago.

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?


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.


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


plural for table names - because tables store users, products, items, and so on. singular names for models as they are single item - User, Product, Item. for table fields I conform to mysql naming convention - user_id, product_price, item_count.

Use any of them, but use consistently - that would be my answer after all.


The standard pattern for LINQ to SQL (and EF,presumably), Ruby/Rails, etc. -- that is frameworks that choose convention over configuration -- is to use plural table names.


I usually name the table depending on how I intuitively relate to it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号