Table Naming Dilemma: Singular vs. Plural Names [closed]

Asked 2023-09-21 08:11:18 View 753,468

Academia has it that table names should be the singular of the entity that they store attributes of.

I dislike any T-SQL that requires square brackets around names, but I have renamed a Users table to the singular, forever sentencing those using the table to sometimes have to use brackets.

My gut feel is that it is more correct to stay with the singular, but my gut feel is also that brackets indicate undesirables like column names with spaces in them etc.

Should I stay, or should I go?

  • I'm surprised that more people aren't saying: it's determined by what single row represents. In a single database I may have a table who's rows represent single a single widget, and another who's one-to-many relationship to that table means rows represent many widgets. Not doing this looses expressiveness. - anyone
  • I just want to add that in all of these discussions, please note that a table in no way shape or form the same as a class. A table is a collection of elements of a specific type that can be sorted, queried, etc. on individual properties. A class is the framework to describe the properties and behaviour OF a specific type. In OO coding terms the closes representation to a table is a collection of objects.(no matter what ORM you may be using). This is by far the highest ranking google answer on this subject, so although the question is closed, the page still has value. - anyone
  • I would go for the common practice of the ecosystem you are working in. For example: In Node.js ORMs like Bookshelf.js or Objection.js are mainly based on "Knex.js". And in the "Knex.js" documentation you will find table names in plural. So I would go for plural in that domain. Source: knexjs.org/#Schema-createTable - anyone
  • Yes I agree. It makes sense to have a table of users and call it "AppUser" at the same time it also makes sense to have a table of rules applicable to a particular type of user and call it "UserRules" - anyone
  • @Arindam "UserRule" or "UsersRule" definitely doesn't sound right as a name for a list of user-related rules. Now that is a strong argument against always using the singular form! - anyone

Answers

I had same question, and after reading all answers here I definitely stay with SINGULAR, reasons:

Reason 1 (Concept). You can think of bag containing apples like "AppleBag", it doesn't matter if contains 0, 1 or a million apples, it is always the same bag. Tables are just that, containers, the table name must describe what it contains, not how much data it contains. Additionally, the plural concept is more about a spoken language one (actually to determine whether there is one or more).

Reason 2. (Convenience). it is easier come out with singular names, than with plural ones. Objects can have irregular plurals or not plural at all, but will always have a singular one (with few exceptions like News).

  • Customer
  • Order
  • User
  • Status
  • News

Reason 3. (Aesthetic and Order). Specially in master-detail scenarios, this reads better, aligns better by name, and have more logical order (Master first, Detail second):

  • 1.Order
  • 2.OrderDetail

Compared to:

  • 1.OrderDetails
  • 2.Orders

Reason 4 (Simplicity). Put all together, Table Names, Primary Keys, Relationships, Entity Classes... is better to be aware of only one name (singular) instead of two (singular class, plural table, singular field, singular-plural master-detail...)

  • Customer
  • Customer.CustomerID
  • CustomerAddress
  • public Class Customer {...}
  • SELECT FROM Customer WHERE CustomerID = 100

Once you know you are dealing with "Customer", you can be sure you will use the same word for all of your database interaction needs.

Reason 5. (Globalization). The world is getting smaller, you may have a team of different nationalities, not everybody has English as a native language. It would be easier for a non-native English language programmer to think of "Repository" than of "Repositories", or "Status" instead of "Statuses". Having singular names can lead to fewer errors caused by typos, save time by not having to think "is it Child or Children?", hence improving productivity.

Reason 6. (Why not?). It can even save you writing time, save you disk space, and even make your computer keyboard last longer!

  • SELECT Customer.CustomerName FROM Customer WHERE Customer.CustomerID = 100
  • SELECT Customers.CustomerName FROM Customers WHERE Customers.CustomerID = 103

You have saved 3 letters, 3 bytes, 3 extra keyboard hits :)

And finally, you can name those ones messing up with reserved names like:

  • User > LoginUser, AppUser, SystemUser, CMSUser,...

Or use the infamous square brackets [User]

Answered   2023-09-21 08:11:18

  • I'll bet if you put a label on a sock drawer you'd call it "Socks". - anyone
  • Definetelly. It is difficult to get one standard that works for all and for everybody, important is that works for you. This works for me, and here I have explained why, but again, that is for me, and I find it very convenient. - anyone
  • The bigger question Chris, is why would you follow database naming conventions when naming a sock drawer? - anyone
  • This answer needs more praise. It discusses a bunch of practical reasons that I apply to why I prefer singular names. The alternate discussions about proper language in reference to sets are just philosophical and are obscuring the real point. Singular just works better. - anyone
  • I have a "Sock" drawer at home, not a "Socks" drawer. If it were a database, I'd call it the "Sock" table. - anyone

I prefer to use the uninflected noun, which in English happens to be singular.

Inflecting the number of the table name causes orthographic problems (as many of the other answers show), but choosing to do so because tables usually contain multiple rows is also semantically full of holes. This is more obvious if we consider a language that inflects nouns based on case (as most do):

Since we're usually doing something with the rows, why not put the name in the accusative case? If we have a table that we write to more than we read, why not put the name in dative? It's a table of something, why not use the genitive? We wouldn't do this, because the table is defined as an abstract container that exists regardless of its state or usage. Inflecting the noun without a precise and absolute semantic reason is babbling.

Using the uninflected noun is simple, logical, regular and language-independent.

Answered   2023-09-21 08:11:18

  • Probably the most logical argument on this subject I've ever seen, and makes me glad I spent that time on Latin. +1 for sure. - anyone
  • Well I clearly need to beef up my vocabulary. - anyone
  • +1 See, these are the kinds of answers the Internet needs more of. Impeccable proofs using rich vocabulary to execute perfect logic. - anyone
  • I'll take note of this next time I'm programming in Latin. In the meantime users will go into the users table and customers into the customers table. - anyone
  • Convinced – uninflected it is. Interesting to see that after all this time, the popular choices of "singular" and "plural" are both wrong! - anyone

If you use Object Relational Mapping tools or will in the future I suggest Singular.

Some tools like LLBLGen can automatically correct plural names like Users to User without changing the table name itself. Why does this matter? Because when it's mapped you want it to look like User.Name instead of Users.Name or worse from some of my old databases tables naming tblUsers.strName which is just confusing in code.

My new rule of thumb is to judge how it will look once it's been converted into an object.

one table I've found that does not fit the new naming I use is UsersInRoles. But there will always be those few exceptions and even in this case it looks fine as UsersInRoles.Username.

Answered   2023-09-21 08:11:18

  • I voted down and I'll tell you why, because I disagree. ORM by it's very nature is about mapping. Every ORM tool that I've ever used supports specifying the table name to be used for an entity when it is different from the entity's name. This is important because the whole reason we map to relational databases is so that we can easily make ad-hoc queries and reports with different shapes than our object model. Otherwise we'd all just be using object/document databases by now. - anyone
  • The ORM should not dictate the names of the objects they map to. The point of ORM is an abstraction of the object, granting this flexibilty. - anyone
  • In my world I try to use consistent names across the whole project to avoid wasting time wondering if this instance has an s on the end or not. The fact that an ORM can rename and be independent doesnt mean that doing so is helping your fellow developers. - anyone
  • Some ORM (like many programming tools) have default behavior that generates implementations without configuration... with the selling point of PRODUCTIVITY. So creating an Employee class, without explicit mapping, would generate an Employee table by default - anyone
  • @barrypicker. Plural names don't just look dumb in ORM code. Plurals look bad in SQL too, especially when referring to a unique attribute. Who's never written select user.id from users? Or perhaps ...from users left join on thingy.user_id = user.id...? - anyone

Others have given pretty good answers as far as "standards" go, but I just wanted to add this... Is it possible that "User" (or "Users") is not actually a full description of the data held in the table? Not that you should get too crazy with table names and specificity, but perhaps something like "Widget_Users" (where "Widget" is the name of your application or website) would be more appropriate.

Answered   2023-09-21 08:11:18

  • I agree. OrgUsers, AppUsers, anything to avoid using a keyword. - anyone
  • -1. Table Users (and Countries, Languages) can be used in few applications simultaneously. - anyone
  • Wouldn't associating schema name would remove all the confusion? AppName1.Users, AppName2.Users ? - anyone
  • I disagree with the table prefix -- that should perhaps be a schema? -- but I agree with a "more descriptive name". Even something as simple as "AppUser" would be sufficient, without entering the entire namespace debate. - anyone
  • This accepted answer is more of a side-comment and doesn't answer the question. - anyone

What convention requires that tables have singular names? I always thought it was plural names.

A user is added to the Users table.

This site agrees:
http://vyaskn.tripod.com/object_naming.htm#Tables

This site disagrees (but I disagree with it):
http://justinsomnia.org/writings/naming_conventions.html


As others have mentioned: these are just guidelines. Pick a convention that works for you and your company/project and stick with it. Switching between singular and plural or sometimes abbreviating words and sometimes not is much more aggravating.

Answered   2023-09-21 08:11:18

  • When applying set theory to tables, any instance in the set is representative of the set, so Apple is an Apple set, it is agnostic of how many apples are in the set - it is an Apple with many instances. A 'bag' of apples doesn't become a 'bags' when it contains many apples. - anyone
  • What if you have a bag with 5 apples inside? Do you call it a bag of apple? or a bag of apples? - anyone
  • I think the theory would be that the set is named Apples. A singular apple is still "a set of Apples" - albeit, a set with a single instance. Multiple apples are also a "set of Apples". - anyone
  • @Christopher, if the raison d'être of the bag is to hold apples and only apples, then it is an "apple bag" , regardless of whether it contains 1 apple, 100 apples or no apples. - anyone
  • @ Ian: That's because a table is generic, and can be compared to a shipping container (can contain nearly anything, from apple crates to crates of Harley Davidson motorcycles). You say: a cargo container of oranges, not an orange cargo container. You say: a cargo container of car parts, not a car parts cargo container. If you made a custom data structure meant to hold only a specific type of data, such as names of apples, and you named it "kungabogo", then you could have an apple kungaboko. I know what your thinking, but think first of a sac of balls, and understand the difference in meaning. - anyone

How about this as a simple example:

SELECT Customer.Name, Customer.Address FROM Customer WHERE Customer.Name > "def"

vs.

SELECT Customers.Name, Customers.Address FROM Customers WHERE Customers.Name > "def"

The SQL in the latter is stranger sounding than the former.

I vote for singular.

Answered   2023-09-21 08:11:18

  • In that example, yes, but in practical sql it would never be written that way. You'd have a table alias so it'd be more like SELECT C.Name, C.Address FROM Customers WHERE Customers.Name > 'def' - anyone
  • I think the sql sounds better plural. You wouldn't have table names for each column, why do you like typing so much. SELECT Name, Address FROM Customers WHERE Name > "def" You're selecting from the pool of customers where the name greater then def. - anyone
  • How about using an alias/AS to get around that one issue? SELECT Customer.Name, Customer.Address FROM Customers AS Customer WHERE Customer.Name > "def" - anyone
  • The second one sounds much better, singular sounds like someone who can't speak English. - anyone
  • I know this is old, but if you think about it it's select every customer's name, customer's address from the customers table. By using plural, you always remember that it will be a set that is returned, even if this set contains only one item. - anyone

I am of the firm belief that in an Entity Relation Diagram, the entity should be reflected with a singular name, similar to a class name being singular. Once instantiated, the name reflects its instance. So with databases, the entity when made into a table (a collection of entities or records) is plural. Entity, User is made into table Users. I would agree with others who suggested maybe the name User could be improved to Employee or something more applicable to your scenario.

This then makes more sense in a SQL statement because you are selecting from a group of records and if the table name is singular, it doesn't read well.

Answered   2023-09-21 08:11:18

  • I especially like the SQL statement comment. Using singular here does not feel intuitive to the reader. - anyone
  • Excellent point about the ERD. I suspect this is why, to someone who sees the world through DBA eyes, singular naming makes sense. I suspect they don't get, as you point out, the difference between an entity and a collection of them. - anyone
  • A table is not a collections of records; a table is a definition of what a record looks like. That's the disconnect all the plural/singular folk seem to have. - anyone
  • One old_lady has many cat OR old_ladies have cats. I think ERDs read nicer as plural. And table of entities, tables have many entities so again I think plural sounds nice. - anyone
  • Look up relational database terminology and why we should use the word "relation" instead of "table". - anyone

IMHO, table names should be plural like Customers.

Class names should be singular like Customer if it maps to a row in the Customers table.

Answered   2023-09-21 08:11:18

I stick with singular for table names and any programming entity.

The reason? The fact that there are irregular plurals in English like mouse ⇒ mice and sheep ⇒ sheep. Then, if I need a collection, i just use mouses or sheeps, and move on.

It really helps the plurality stand out, and I can easily and programatically determine what the collection of things would look like.

So, my rule is: everything is singular, every collection of things is singular with an s appended. Helps with ORMs too.

Answered   2023-09-21 08:11:18

  • what about a word ending with a 's'? If you have a table called 'News' (just as an example), what would you call the collection of news? Newss? Or would you call the table 'New'? - anyone
  • I would call the table NewsItem and a collection NewsItems. - anyone
  • What if you have to spell-check all code or else it will not compile ;) ? - anyone
  • The ORM should not dictate the names of the objects they map to. The point of ORM is an abstraction of the object, granting this flexibilty. - anyone
  • @HamishGrubijan then stop using Word to write your code! ;) - anyone

Singular. I don't buy any argument involving which is most logical - every person thinks his own preference is most logical. No matter what you do it is a mess, just pick a convention and stick to it. We are trying to map a language with highly irregular grammar and semantics (normal spoken and written language) to a highly regular (SQL) grammar with very specific semantics.

My main argument is that I don't think of the tables as a set but as relations.

So, the AppUser relation tells which entities are AppUsers.

The AppUserGroup relation tells me which entities are AppUserGroups

The AppUser_AppUserGroup relation tells me how the AppUsers and AppUserGroups are related.

The AppUserGroup_AppUserGroup relation tells me how AppUserGroups and AppUserGroups are related (i.e. groups member of groups).

In other words, when I think about entities and how they are related I think of relations in singular, but of course, when I think of the entities in collections or sets, the collections or sets are plural.

In my code, then, and in the database schema, I use singular. In textual descriptions, I end up using plural for increased readability - then use fonts etc. to distinguish the table/relation name from the plural s.

I like to think of it as messy, but systematic - and this way there is always a systematically generated name for the relation I wish to express, which to me is very important.

Answered   2023-09-21 08:11:18

  • exactly. the main thing many people are not aware here is what they are naming... you are giving name to a relation (a single record in the table), not the set of records in the table. - anyone
  • Couldn't disagree more. 'Select * from Users where Name like 'J%'' because I am selecting all users where the name starts with 'J'. If your argument is that you want to write '...where User.Name like...' then simply use an alias. Same reason I say 'Give me a pair from all available socks.' - anyone
  • If I was that particular my table name would be sock_pair - anyone
  • @AlexandreMartini Exactly. Like some people who call a single record in the table "relation". - anyone

I also would go with plurals, and with the aforementioned Users dilemma, we do take the square bracketing approach.

We do this to provide uniformity between both database architecture and application architecture, with the underlying understanding that the Users table is a collection of User values as much as a Users collection in a code artifact is a collection of User objects.

Having our data team and our developers speaking the same conceptual language (although not always the same object names) makes it easier to convey ideas between them.

Answered   2023-09-21 08:11:18

  • I agree.. why the inconsistency between code and storage? I would never name a collection of user objects "User" in code... so why would I call a table that? It makes no sense. When I read the arguments above about it, they are focusing on the entity, not the table... there is a distinction between whats in the table than the table itself in my mind. - anyone
  • How do you deal with a table name like companies where other tables have a referencing field called company_id? While it's properly spelled, it seems inconsistent for those that are picky about table naming conventions. - anyone
  • By remembering that the singular of companies is company, and that this id is a reference to a singular item. It shouldn't bother us in code any more than it bothers us in English. - anyone
  • In the past I often saw code where the plural of company has been companys for that reason. But this will no longer work with IDEs that do spell checking 😉 - anyone

I personaly prefer to use plural names to represent a set, it just "sounds" better to my relational mind.

At this exact moment i am using singular names to define a data model for my company, because most of the people at work feel more confortable with it. Sometimes you just have to make life easier to everyone instead of imposing your personal preferences. (that's how i ended up in this thread, to get a confirmation on what should be the "best practice" for naming tables)

After reading all the arguing in this thread, i reached one conclusion:

I like my pancakes with honey, no matter what everybody's favorite flavour is. But if i am cooking for other people, i will try to serve them something they like.

Answered   2023-09-21 08:11:18

  • It is not wise to use such convention in relational model world, especially when you describe relation between objects, e.g. "Each Team may have only one Main Coach and many secondary Coaches" , which is described: Team->MainCoach , Team->>SecondaryCoach - anyone

I've actually always thought it was popular convention to use plural table names. Up until this point I've always used plural.

I can understand the argument for singular table names, but to me plural makes more sense. A table name usually describes what the table contains. In a normalized database, each table contains specific sets of data. Each row is an entity and the table contains many entities. Thus the plural form for the table name.

A table of cars would have the name cars and each row is a car. I'll admit that specifying the table along with the field in a table.field manner is the best practice and that having singular table names is more readable. However in the following two examples, the former makes more sense:

SELECT * FROM cars WHERE color='blue'
SELECT * FROM car WHERE color='blue'

Honestly, I will be rethinking my position on the matter, and I would rely on the actual conventions used by the organization I'm developing for. However, I think for my personal conventions, I'll stick with plural table names. To me it makes more sense.

Answered   2023-09-21 08:11:18

  • Isn't this the convention in RoR too? Plural names for tables and Singular for ORM classes? Makes a lot of sense to me. Table is called "cars" because it has many instances of "car" and class is called "Car" because it will hold one instance of a car!! - anyone
  • @Sap A minor correction of the latter part of your sentence - The class "Car" is an Abstract DataType representing a real-life Car. Whether it'll hold one instance or multiples depends on how it's used. - anyone
  • lets face it, table car is a definition of the structure of a single car. If you look at the structure of the table, it will spit out basically "id int, color string etc" furthermore: say you have a table car_vendor (or for your plural version it would be cars_vendor) with the foreign key cars_id ?! what is that stupid shit? it is car_id no need to make me think. Singular is strongly preferred by me - anyone
  • I really like this answer! Let me explain. If the collection is car and you want everything from the car that is blue the result should be something like tire, mirror, engine. And then it is getting confusing because all results are parts from a car. So the table name should be carparts (or car_parts, CarParts whatever you like) - anyone
  • Any database designer who enforces singular table names is basically declaring war against any Ruby on Rails app developers who may come into touch with that database in the future. Rail's strict insistence on singular words for classes, and pluralized names for tables, enables a lot of powerful behaviour within many gems inside Ruby's ecosystem. So even if you think singular sounds better, for the sake of compatibility you should stick to plural. I imagine this holds true for many other Object Relational Mappers too. - anyone

Singular. I'd call an array containing a bunch of user row representation objects 'users', but the table is 'the user table'. Thinking of the table as being nothing but the set of the rows it contains is wrong, IMO; the table is the metadata, and the set of rows is hierarchically attached to the table, it is not the table itself.

I use ORMs all the time, of course, and it helps that ORM code written with plural table names looks stupid.

Answered   2023-09-21 08:11:18

  • To each his own, I guess. A relational database table is by definition a heading (i.e. metadata naming the attributes) and a set of tuples matching the heading. You can focus on the metadata, whereas other folks focus on the tuples. :-) - anyone
  • Hey, User_Table is a name I like! :) - anyone
  • The ORM should not dictate the names of the objects they map to. The point of ORM is an abstraction of the object, granting this flexibilty. - anyone
  • I look at it this way.. if you create an array/list/dictionary of anything in code, my bet is you name it with the plural name of whatever it holds. If you are using an ORM to abstract your database, tables are represented with some sort of collection, so why would you treat them any different? To use singular names may sound good, but you are always fighting your instinct that a table holds many of the same thing, just like a collection in code does. Why the inconsistency? - anyone
  • @barrypicker The grammar should not dictate the programming conventions (do you know the java beans is/get idiocy?). It should be followed as long as it doesn't come into way. The possibility to use a different mapping in an ORM is there for cases when it's needed. Grammar is much to irregular and things like "matrixes" vs "matrices" are rare but strong examples for why the code shouldn't be infested by it. - anyone

I don't like plural table names because some nouns in English are not countable (water, soup, cash) or the meaning changes when you make it countable (chicken vs a chicken; meat vs bird). I also dislike using abbreviations for table name or column name because doing so adds extra slope to the already steep learning curve.

Ironically, I might make User an exception and call it Users because of USER (Transac-SQL), because I too don't like using brackets around tables if I don't have to.

I also like to name all the ID columns as Id, not ChickenId or ChickensId (what do plural guys do about this?).

All this is because I don't have proper respect for the database systems, I am just reapplying one-trick-pony knowledge from OO naming conventions like Java's out of habit and laziness. I wish there were better IDE support for complicated SQL.

Answered   2023-09-21 08:11:18

  • Us plural guys either name the 'id' column 'id' like you do, or 'singular_id'. I believe tables should be plural (think of them like arrays), but column names should be singular (attributes of a single element). - anyone
  • plu_ral/PluRal for table names, singular_id/singularId for primary keys. - anyone

We run similar standards, when scripting we demand [ ] around names, and where appropriate schema qualifiers - primarily it hedges your bets against future name grabs by the SQL syntax.

SELECT [Name] FROM [dbo].[Customer] WHERE [Location] = 'WA'

This has saved our souls in the past - some of our database systems have run 10+ years from SQL 6.0 through SQL 2005 - way past their intended lifespans.

Answered   2023-09-21 08:11:18

  • Seems like ritualistic self-flagellation. Has any such name grabs happened yet? - anyone

Tables: plural

Multiple users are listed in the users table.

Models: singular

A singular user can be selected from the users table.

Controllers: plural

http://myapp.com/users would list multiple users.

That's my take on it anyway.

Answered   2023-09-21 08:11:18

  • Closer to my take, but mine is that the table's storage of multiple users is actually incidental, and that any singular user is represented by the table, or rather the relation that is a set of tuples representing a User entity. - anyone
  • I think I tend to agree with this. The only thing confuses me is why should models be singular? Only if the model is only concerned with a single User. If I was querying the db to get all users then would I need to access the model? It does not make sense for a singular instance to fetch all records, example: $user->get_all() //does not make sense - anyone

If we look at MS SQL Server's system tables, their names as assigned by Microsoft are in plural.

The Oracle's system tables are named in singular. Although a few of them are plural. Oracle recommends plural for user-defined table names. That doesn't make much sense that they recommend one thing and follow another. That the architects at these two software giants have named their tables using different conventions, doesn't make much sense either... After all, what are these guys ... PhD's?

I do remember in academia, the recommendation was singular.

For example, when we say:

select OrderHeader.ID FROM OrderHeader WHERE OrderHeader.Reference = 'ABC123'

maybe b/c each ID is selected from a particular single row ...?

Answered   2023-09-21 08:11:18

  • Microsoft are what they are for business reasons first (and often unethical reasons at that), logical reasons last. My only reason for following them would be that they are the big gorilla and everyone else goes that way. When I have a choice, I choose the other way. - anyone
  • Two things. One, you normally wouldn't use the table names and would write 'select ID FROM OrderHeaders WHERE Reference = 'ABC123' because you are 'Selecting all IDs from OrderHeaders where something is true' but if you had to use table names because of a join or whatever, you would use an alias like so... 'select OrderHeader.ID FROM OrderHeaders as OrderHeader WHERE OrderHeader.Reference = 'ABC123' - anyone

The system tables/views of the server itself (SYSCAT.TABLES, dbo.sysindexes, ALL_TABLES, information_schema.columns, etc.) are almost always plural. I guess for the sake of consistency I'd follow their lead.

Answered   2023-09-21 08:11:18

  • Microsoft are what they are for business reasons first (and often unethical reasons at that), logical reasons last. My only reason for following them would be that they are the big gorilla and everyone else goes that way. When I have a choice, I choose the other way. - anyone
  • It should be noted that the information_schema is part of ISO/IEC 9075-11, the SQL standard. And yes, it does use plural tables/views names. - anyone

I've always used singular simply because that's what I was taught. However, while creating a new schema recently, for the first time in a long time, I actively decided to maintain this convention simply because... it's shorter. Adding an 's' to the end of every table name seems as useless to me as adding 'tbl_' in front of every one.

Answered   2023-09-21 08:11:18

I am a fan of singular table names as they make my ER diagrams using CASE syntax easier to read, but by reading these responses I'm getting the feeling it never caught on very well? I personally love it. There is a good overview with examples of how readable your models can be when you use singular table names, add action verbs to your relationships and form good sentences for every relationships. It's all a bit of overkill for a 20 table database but if you have a DB with hundreds of tables and a complex design how will your developers ever understand it without a good readable diagram?

http://www.aisintl.com/case/method.html

As for prefixing tables and views I absolutely hate that practice. Give a person no information at all before giving them possibly bad information. Anyone browsing a db for objects can quite easily tell a table from a view, but if I have a table named tblUsers that for some reason I decide to restructure in the future into two tables, with a view unifying them to keep from breaking old code I now have a view named tblUsers. At this point I am left with two unappealing options, leave a view named with a tbl prefix which may confuse some developers, or force another layer, either middle tier or application to be rewritten to reference my new structure or name viewUsers. That negates a large part of the value of views IMHO.

Answered   2023-09-21 08:11:18

  • Good example of a pitfall of prefixing object names with a 'type' qualifier! - anyone

I once used "Dude" for the User table - same short number of characters, no conflict with keywords, still a reference to a generic human. If I weren't concerned about the stuffy heads that might see the code, I would have kept it that way.

Answered   2023-09-21 08:11:18

  • You just gave me an idea! Lol - anyone
  • haha I love it, only that it's less generic and inclusive, even though I know there's many saying dude to women, this is not necessarily the case for everyone 😉 - anyone

This may be a bit redundant, but I would suggest being cautious. Not necessarily that it's a bad thing to rename tables, but standardization is just that; a standard -- this database may already be "standardized", however badly :) -- I would suggest consistency to be a better goal given that this database already exists and presumably it consists of more than just 2 tables.

Unless you can standardize the entire database, or at least are planning to work towards that end, I suspect that table names are just the tip of the iceberg and concentrating on the task at hand, enduring the pain of poorly named objects, may be in your best interest --

Practical consistency sometimes is the best standard... :)

my2cents ---

Answered   2023-09-21 08:11:18

As others have mentioned here, conventions should be a tool for adding to the ease of use and readability. Not as a shackle or a club to torture developers.

That said, my personal preference is to use singular names for both tables and columns. This probably comes from my programming background. Class names are generally singular unless they are some sort of collection. In my mind I am storing or reading individual records in the table in question, so singular makes sense to me.

This practice also allows me to reserve plural table names for those that store many-to-many relationships between my objects.

I try to avoid reserved words in my table and column names, as well. In the case in question here it makes more sense to go counter to the singular convention for Users to avoid the need to encapsulate a table that uses the reserved word of User.

I like using prefixes in a limited manner (tbl for table names, sp_ for proc names, etc), though many believe this adds clutter. I also prefer CamelBack names to underscores because I always end up hitting the + instead of _ when typing the name. Many others disagree.

Here is another good link for naming convention guidelines: http://www.xaprb.com/blog/2008/10/26/the-power-of-a-good-sql-naming-convention/

Remember that the most important factor in your convention is that it make sense to the people interacting with the database in question. There is no "One Ring to Rule Them All" when it comes to naming conventions.

Answered   2023-09-21 08:11:18

  • Ignoring the horrors of hungarian notation. Never, never, never use sp_ in front of stored procedures because MS-SQL uses that for system stored procedures and treats them special. Since sp_ are stored in the master table, MS-SQL always looks thier first even if you qualify the location. - anyone

Possible alternatives:

  • Rename the table SystemUser
  • Use brackets
  • Keep the plural table names.

IMO using brackets is technically the safest approach, though it is a bit cumbersome. IMO it's 6 of one, half-a-dozen of the other, and your solution really just boils down to personal/team preference.

Answered   2023-09-21 08:11:18

  • I like your 'prefix' idea, but would call it SystemUser. - anyone

My take is in semantics depending on how you define your container. For example, A "bag of apples" or simply "apples" or an "apple bag" or "apple".

Example: a "college" table can contain 0 or more colleges a table of "colleges" can contain 0 or more collegues

a "student" table can contain 0 or more students 
a table of "students" can contain 0 or more students.

My conclusion is that either is fine but you have to define how you (or people interacting with it) are going to approach when referring to the tables; "a x table" or a "table of xs"

Answered   2023-09-21 08:11:18

I think using the singular is what we were taught in university. But at the same time you could argue that unlike in object oriented programming, a table is not an instance of its records.

I think I'm tipping in favour of the singular at the moment because of plural irregularities in English. In German it's even worse due to no consistent plural forms - sometimes you cannot tell if a word is plural or not without the specifying article in front of it (der/die/das). And in Chinese languages there are no plural forms anyway.

Answered   2023-09-21 08:11:18

  • In university I am taught plural for tables, I also have a book here, DB management third edition from the 90's, tables are singular; while I also have an updated copy, 11e, singular and some abbreviated names, while the XML section uses plural. \n But if you check the actual content for the RDBMS sections, it's literally still the same text with some images having gotten a face lift. \n The "data modelling checklist" states nothing on plural vs singular, just that entities should only map to a single object, that's probably what they were trying to enforce in the books. - anyone

I only use nouns for my table names that are spelled the same, whether singular or plural:

moose fish deer aircraft you pants shorts eyeglasses scissors species offspring

Answered   2023-09-21 08:11:18

I always thought that was a dumb convention. I use plural table names.

(I believe the rational behind that policy is that it make it easier for ORM code generators to produce object & collection classes, since it is easier to produce a plural name from a singular name than vice-versa)

Answered   2023-09-21 08:11:18

  • This convention has been part of relational theory long, long, before ORM ever existed. - anyone
  • The ORM should not dictate the names of the objects they map to. The point of ORM is an abstraction of the object, granting this flexibilty. - anyone

I did not see this clearly articulated in any of the previous answers. Many programmers have no formal definition in mind when working with tables. We often communicate intuitively in terms of of "records" or "rows". However, with some exceptions for denormalized relations, tables are usually designed so that the relation between the non-key attributes and the key constitutes a set theoretic function.

A function can be defined as a subset of a cross-product between two sets, in which each element of the set of keys occurs at most once in the mapping. Hence the terminology arising from from that perspective tends to be singular. One sees the same singular (or at least, non-plural) convention across other mathematical and computational theories involving functions (algebra and lambda calculus for instance).

Answered   2023-09-21 08:11:18