Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

I have trouble naming the COUNT() column from SQL queries and will swap between various variants

  • _Count
  • [Count] (sql, or "count" or backticks for MySQL etc)
  • C
  • Cnt
  • CountSomething (where "something" is the field being counted, or "CountAll")
  • NoOfRows
  • RowCount
  • etc

Has anyone come up with any name that you are happy with and always use without hesitation?
This is bothering me because after joining SO just recently, my answers have shown this tendency of flip-flopping with no consistency.
I need to get this sorted.

Please help.

(While we're at it, what do you use for SUM etc?)

Note: Before you close this question, consider that this one was not:

What's the best name for a non-mutating “add” method on an immutable collection?

share

migration rejected from stackoverflow.com Aug 5 at 2:46

This question came from our site for professional and enthusiast programmers. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

closed as primarily opinion-based by MichaelT, gnat, durron597, GlenH7, Snowman Aug 5 at 2:46

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

3  
@cyberkiwi: if we tell you the correct name for the COUNT(*) column, do you promise you will be using it? –  Quassnoi Jan 31 '11 at 22:12
1  
@omg "End users can not mark questions wiki anymore" (The CW checkbox only exists on answers these days) –  Martin Jan 31 '11 at 22:24
2  
@cyberkiwi: there is a street in London, GROUP cnt lane or something like this. Was inhabited by SQL developers in XIV century, hence the name. –  Quassnoi Jan 31 '11 at 22:27
1  
@Martin: Thx, I never read meta –  OMG Ponies Jan 31 '11 at 22:37
1  
This may be the best comment thread I've read all morning after all. –  BoltClock Jan 31 '11 at 23:18

1 Answer 1

"If there are more than two instances of COUNT/SUM/etc in the query, how do you distinguish between them?"

When you contemplate that question, it becomes obvious that:

  • using a naming convention consistently matters
  • the naming convention should be informational enough to distinguish from other uses of the same function

With the advent of intellisense/etc in SQL IDEs like SSMS and PLSQL Developer, I tend to prefix my aggregate derived columns. IE: numUsers, or cntUsers This makes it easier to key to them without sifting through others.

share

Not the answer you're looking for? Browse other questions tagged or ask your own question.