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.
精彩评论