views:

2386

answers:

21

I am trying to find a better approach for storing people's name in the table. What is the benefits of 3 field over 1 field for storing persons name?

thanks.

+5  A: 

You may want to search on the 3 separate fields for one and its inexpensive to concatenate for the fullname.

e.g. If you want to search for all the Mr. Nolans your query would be

SELECT Title+' '+FirstName+' '+Surname As FullName  
from table where firstname = 'Mr' and surname ='Nolan'

to do this with just the fullnames would be a pain.

John Nolan
In addition, you may want to sort on various aspects of a name and you can't do that if it is all in a single column.
Dillie-O
It would probably only be a pain if you had very low resources, or were storing all the Western names in existence, and regularly searching them :)
Bobby Jack
@Dillie-O that's speculative generality, more likely than not YAGNI.
Wedge
+48  A: 

You can always construct a full name from its components, but you can't always deconstruct a full name into its components.

Say you want to write an email starting with "Dear Richie" - you can do that trivially if you have a given_name field, but figuring out what someone's given name is from their full name isn't trivial.

You can also trivially search or sort by given_name, or family_name, or whatever.

(Note I'm using given_name, family_name, etc. rather than first_name, last_name, because different cultures put their names in different orders.)

Solving this problem in the general case is hard - here's an article that gives a flavour of how hard it is: Representing People's Names in Dublin Core.

RichieHindle
You can't construct a full name from three components if the name has more than three components.
John Saunders
But you can constrain users to enter the data for storage in a 3-component format.
Joel Coehoorn
Yes but then its up to you to allow for n 'middle' names
David Archer
Just a plug for suffixes like Jr.and III here, too.
Anon
If your users can come from Asia, 3 name fields might not line up with their names.
James Socol
@Joel: yes you can constrain them to enter their names as though Western-style names are somehow better than theirs. I figure that "they" outnumber "us" by some margin, so I'd rather not. Besides, I agree with Anon about "III". I know two computer systems that have my surname as "Saunders, III". I do not like them.
John Saunders
The lesson is, unless you REALLY need to say "Dear John,", store name as a single field.
Bobby Jack
The idea is to allow the user natural way of data entry, so I prefer full name rather than first and last name data entry; a live example would be Microsoft outlook, which allow user to enter name as full name. But don’t know whether they store name as first and last name or as a full name. During my 15 years of software development I never liked the idea of Last name, First name approach.
ashraf
Actually "middlename" in the exact sense is only known in the U.S., as far as I know. It does not quite match with the concept of a second (third..., n-th) name that for example Europeans have. Middlename can be something weird like "littlepage" where as a second name is just a second first name (for what ever reasons it might ever be needen).
raoulsson
Most government forms here in Australia have fields for "Family Name", "First Given Name", and "Other Given Names" which allow for more than one middle name ...
phalacee
A: 

Each of the individual names is an atomic piece of data. When they are stored separately then it is easier to print them out in different formats such as Firstname Lastname and Lastname, Firstname.

geofflane
+2  A: 

About the only thing I can think of is for searching purposes. It's a bit better to search a field using [=] rather than say [like].

If you have no need to display the name as seperate words then go with a single field.

But if you need to do something like [Dear Mr. Achu] then perhaps a 3 field approach would be better.

griegs
Blimey, by the time I added my comment 3 above me had been added. That's hectic.
griegs
A: 

There is no benefit if you never need to sort or search by first, middle, or last name.

le dorfier
A: 

Flexibility.

e.g. If someone had a double barreled last name and no middle name.

Smalltown2000
+2  A: 

Keeping the fields separate allows you to support different output formats and cultures where the family name is written first

Ken Keenan
+3  A: 

Most of the time it's there to support writing form letters like, "Mr. so-and-so", or to search/sort by last name which is very common.

Given that first/middle/last may not apply to all cultures, there could be a better approach. It might be better expressed as "informal name" / "formal name" / "legal name" or something like that.

Still, at this point first/middle/last is very common, and from a data entry standpoint it is what everyone expect.

Chris Arguin
A: 

To me it is simply better to store 3 names so that explicit parsing is necessary later on if the individual components are needed..

+8  A: 

As others have said, how do you decompose a full name in to its component parts.

  • Colin Angus Mackay
  • Jean Michel Jarre
  • Vincent van Gogh
  • Pablo Diego José Francisco de Paula Juan Nepomuceno María de los Remedios Cipriano de la Santísima Trinidad Ruiz y Picasso

How do you reliably decompose that lot?

Colin Mackay
You provide the user with three input fields and let them get on with it. 8-)
RichieHindle
That's not very culturally sensitive.
John Saunders
John, meet my smiley. Smiley, meet John.
RichieHindle
Oh, I see. I didn't get the "8". Sorry
John Saunders
Talking about Culture, in the old day and living in old Europe, how many times did i have to come up with U.S. state zip codes that pleased the signup profile.... gosh.... I had a bookmark listing me all of them ready at all times. It got a lot better within the last 10 years though I must admit.
raoulsson
(or probably cities :-))
raoulsson
@John: I wear glasses. Possibly I shouldn't attempt to represent that in my smilies.
RichieHindle
@Ritchie: So do I, but I guess my smilies hide that fact. ;-) could be me today, squinting, instead of winking.
John Saunders
+4  A: 

I was looking up the Spanish Civil War the other day, and found this exception to most rules:


Next time I'm working on a system that has to store names, I'm going to try something radical: designing from the requirements.

What are we going to use the names for?

  1. Name on an address label for the postal service
  2. Greeting on the website
  3. Informal name

Based on what the names will be used for, we'd determine how much information to store. Maybe we allow the user to enter all three of those, including line breaks in the first case (Generalissimo Franco might want his full titles and appointments listed, if he weren't still dead). Maybe we provide First, Middle, Last, Generation as an option, and fill in the rest as defaults. Maybe we offer other common options like Surname, Given Name.

This is in contrast to the old-style First, Middle, Last we've used since before I started programming in COBOL back in 1975, and have "made fit" ever since.

John Saunders
Spanish people often take a surname from each parent. It used to be common for every woman to have María as their first name, so everyone used their middle name as a result otherwise it would get very confusing.
Colin Mackay
Yeah, that's why I included his parents' names. So those not familiar with this style of naming could see where the pieces came from. Still, I bet he would only rarely include "Salgado y Pardo de Andrade".
John Saunders
At that rate, we'll be carrying around an entire serialized genealogy instead of a name!
Jeffrey Hantin
No, this is why I say carry a single "FullName" field, nvarchar(1024), FormalAddressName nvarchar(255), ScreenName nvarchar(50), WelcomeName nvarchar(100), etc. Give good defaults and let the users enter the details if they want to override the defaults.
John Saunders
Sting, Prince, Bono, ?uestlove?
Ash Machine
A: 

You can't always separate surname from full name cleanly and reliably so there's good reason to separate that because you often need surname. After you do that, there are two common approaches:

  1. first_name and middle_name; or
  2. given_names.

(2) is arguably more preferable because people sometimes have more than tow given names and (1) is more inflexible in this regard.

Also, another common field is preferred_name (in addition to the above).

cletus
+16  A: 

Keep your data as clean as you can!

How?

Ask your user only as few things as you absolutely need at the time you ask.

How you store the name does not matter. What does matter is that

  1. the user experience is as good as can be
  2. you don't have false data in your system

If you annoy the users with mandatory fields to fill in and re-question them several times, they can get upset and not buy into your application right there and then. You want to avoid bad user experiences at all times.

No user cares how easy it is for you to search your database for his middle name. He wants to have a easy, feel good experience, that's it.

What do users do if they are forced to input data like their postal address, or even email address when they only want a "read-only" account with no notifications needed? They put garbage data into your system. This will render your super search and sort algorithms useless anyway.

Thus, my advice would be in any app to gather just as little information from your user as you really need in order to serve them, no more.

If for example you run a online shop for pet food, don't ask your users at sign-up what kind of pets they own. Make it an option for them to fill in once they are logged in and all happy (new customers). Don't ask them their postal address until they order stuff that is actually carried to their house, stuff they pay for and thus care that YOU have their exact coordinates.

This will lead to a lot better data quality and this is what you should care about, not technical details the user has no benefit from....

In your example I would just ask for the full name (not sure though) and once the user willingly subscribes to your newsletter, let the user decide how he/she wants to be addressed...

raoulsson
I understand your answer, but I would really hate to receive mailings from a company always addressed as "Dear Colin Angus Mackay". Either "Hi Colin" if they want to be informal, or "Dear Mr. Mackay" if they want to be formal. And anyway, if you ask people for their full name they'll put crap anyway. I had delegates at the last conference I ran with name badges that read "joe blow" (not properly capitalised) or "Supercool John" (which he was really embarrased about when he found out what the "name" field was for!)
Colin Mackay
Yes, but then I would try to make that clear *the moment* they hit the "book me to your conference" button. The example you are giving is exactly what I mean. They signed up to some page with silly data (though funny) and then later signed up for a conference, not knowing their details from two years ago would be used for a name tag (lol). Better for them and the data quality would have been to ask them their (proper) real name *right when they sign up* to the conference aka when they spend their bucks...
raoulsson
Never let anyone have real data on you. Too much information is stored in databases. ;)
WolfmanDragon
right of course there, you are, WolfmanDragon ;-)
raoulsson
but then again, WolfmanDragon, how do you/us know you ever existed...? but this pushes the envelope too far now I guess, maybe should go on SO's "fourth" flavour: "PhilosophersLeftClueless.com" or something ;-)
raoulsson
The idea is to allow the user natural way of data entry, so I prefer full name rather than first and last name data entry; a live example would be Microsoft outlook, which allow user to enter name as full name. But don’t know whether they store name as first and last name or as a full name. During my 15 years of software development I never liked the idea of Last name, First name approach.
ashraf
It's like old XP's approach: "Don't build (code) for the future (but instead *when* it is really needed", just more important as *false data* is a multitudes worse than wrong code (that can be upgraded centrally, by deployment)
raoulsson
Interestingly, Google's contact manager stores only full names, not last/first/middle names, although you can add custom fields for them. This is actually i18n friendly since many cultures don't actually have first/last/middle names.
sigint
This doesn't answer the question in the least.
Georg
A: 

I voted up some of these answers, but if you are looking to avoid repetitive or redundant or messy concatenation in your code, you can always use a computed column in the database or a method in a class which exposes the name consistently reconstructed. If these concatenations are expensive (because you are printing a million statements), you can use a persisted column.

Often you will allow users to specify names like nicknames or friendly names, so that you aren't referring to them by the name in their records or always as Mr. Smith.

It all depends on your requirements. There is no single good answer without the environment it is expected to satisfy.

Cade Roux
+7  A: 

Unfortunately this is kind of like asking what is the best way to store a number in the database. It depends on what you are going to do with it - sometimes you want an int,other times a byte, and sometimes a float. With names it depends on things like what cultures do you expect your users to come from, what you plan on doing with the names (will you be using these names to connect with another system that stores names as "last name, first name"?), and how much you can afford to annoy your users. If this is an internal HR application, you can probably afford to annoy the users a lot, and have a very structured, formal breakdown of name components (there are way more than 3 - don't forget mr/mrs, jr, III, multiple middle names, hyphenated last names, and who knows what else if you are trying to handle names from all cultures. If you have a webapp that users might or might not care about, you can't ask them to care too much.

Peter Recore
+2  A: 

Things like ORDER BY firstname or ORDER BY lastname are possible when you break the name up into multiple fields.

Not as easy to do when you mash all names into one field.

bobobobo
But the point is that the concept of first name and last name are very far from universal. Take a look at http://dublincore.org/documents/1998/02/03/name-representation/.
John Saunders
@John, good article. I like the idea of using the Library of Congress Name Authority File. I will dig deeper into that.
WolfmanDragon
+1  A: 

The i18n issue can be a bugger either way. certain cultures use the surname first and the given name last, that strikes the idea of first and last names so we move to fields for surnames and given names. Wait, some cultures don't have a surname or the surname is modified by the gender of the named.
We can get into tribal cultures where the person is renamed on adulthood. "Sitting Bull" childhood name was "Jumping Badger".
This is somewhat of a ramble but what I am showing is that the more fields you have the more accurate the design is. There should be at least a not null 'given name' field and a optional 'surname' field tied to a PK that is an integer. If the aforementioned requirements are observed, fields can be added without issues of breaking queries.

WolfmanDragon
"We can get into tribal cultures where the person is renamed on adulthood." -- true but understated. Even without tribal culture, a U.S. president might switch his first and middle names.
Windows programmer
Even without tribal culture someone might become the Pope.
Ludwig Weinzierl
So a Pope gets to change his name? I think I have heard something about that. My point exactly, how many situations do we have that we have not thought up?
WolfmanDragon
A: 

Not sure how practical it would be, but maybe if cultural sensitivity is important in the context of the application being developed, perhaps a name should be a collection with each element of the collection carrying a value indicating if the name is the addressable "first name" or the addressable "surname" and so on for "title" or anything else that needs to be identified. A name ID could be used to identify the order of the elements for re-composing the full name.

Lloyd McFarlin
Question: please characterize the contexts in which cultural sensitivity is _not_ an important issue.
John Saunders
Clarification: I'm speaking strictly about this particular scenario where cultural sensitivity matters in the case of name formats. Obviously, there are going to be other sensitivities that have to be accounted for. Many apps developed for a western audience can be well-suited with first, middle and last. People with very large names are often well aware that their names have to be adapted to western systems. Being half-Filipino (where women tend to be named "Maria 2ndName Mid Last"), I'm well aware of this. Even by other Filipinos, none of my aunts or my mom are addressed as "Maria".
Lloyd McFarlin
I don't know this for sure, but I'm even willing to bet that extremely long names have to be adapted to information and registrar systems even in non-Western countries.
Lloyd McFarlin
+1  A: 

Just have two fields, 'Full Name', and 'Preferred Name' - easy. Supports every name in existance (As long as the language has lexical symbols... So, yes, that excludes languages that do not have a written form).

Just make sure that they are handled in some unicode format, and that application code properly handles unicode conversion.

Arafangion
Preferred Name at work is different from Preferred Name at home. Preferred Name with friends depends on how close the friendship is. Preferred Name in correspondence with other countries depends on the language used in correspondence.
Windows programmer
More than likely, either the user will use the database in a professional context, or in a personal context - it would be unusual to mix the two. If they genuinely want a "personal" context even though they use it professionally as well, then I would assume that they would either just use the professional name, with the knowledge that friends will use their personal name anyway, or simply have two accounts.
Arafangion
+1  A: 

Some of the issues can be solved by also storing an additional column like PreferredName. We do that in our DB and also store prefix column and a suffix column. e.g 'Prof Henry W Jones Jnr' with preferred name as 'Indiana Jones'.

Pratik
+2  A: 

Here's the thing, not even humans can get this right all the time, there's just too much data, and too many special cases. I could change my name right now to be 20 parts, with the middle 13 as my "first" name. Parts of names can contain any number of words, and there can be any number of parts of names. Some people only have 1 name (no surname). Some people have lots of middle names. Some people have first or surnames composed of several words. Some people list their surname first. Some people go by their middle name. Some people go by nicknames that aren't obviously related to their given name.

If you try to guess these conventions in software YOU WILL FAIL. Period. Maybe you'll get it right some of the time, maybe even most of the time, but is even that worth it? In my opinion you should store names as one field and stop trying to be cute by using first names to refer to a person. If you need additional information about a name (e.g. a nickname), ask the user!

Wedge
What about sorting? With one field, how do you decide what character to begin the sort with? Arent you then resorting back to "guessing conventions"?
Optimal Solutions
Remember my post talked about the requirements for the name. You want sorting, add a "SortOrder" column (or maybe FileAs).
John Saunders
Let's not even get started on how the Locale affects sorting.
Arafangion