1

When creating a table with similar bits or data such as names. Is it preferred to have the column name prefixed with a common value?

Consider a table to store user information. Looking at the columns related to the users name they may be structured as follows:

title
first_name
middle_name
last_name

Would it not be better to style all columns relating to the users name with 'name' (as shown below) leading to more consistent naming patterns?

name_title
name_first
name_middle
name_last
asked Jun 25, 2016 at 8:28
1
  • 1
    I prefer to name entities as closely as possible to what domain experts call those things. For example, I think the relevant experts and forms that I've seen call it "middle name", not "name middle" (name middle could be interpreted as the middle of a name, which is something else). If you want to group for some other reason, use your own prefix e.g. "x_title", "x_first_name", "x_middle_name" and so on. x is your own prefix which has some convenient meaning to you as a programmer. Commented Jun 25, 2016 at 10:11

2 Answers 2

1

The standard is to use first_name, last_name, etc.

I mean standard not as formally defined (say in ISO 9000) but informally, a usage I have observed over 30 years in dozens of companies and hundreds of systems, thus an informal standard. There's nothing to stop you doing things a different way if it makes sense for your situation, however:

  • Developers already expect names to use the last_name, first_name format in current web pages, scripts and database schemas. When they are that way the developer doesn't need to learn anything new and that makes development easier as they focus on more important code.
  • Other systems mostly use it so interfaces are often easier
  • First time readers don't have to pause to examine the code/data to understand the reason for the unusual naming
  • Most SQL applications that I know, from command line to GUI tools, tend to display database table columns in the order they were listed in the create table (and adjusted by any modify table) commands. Thus the fields are frequently listed together nicely as you would like.
answered Jun 25, 2016 at 13:06
1
  • Great points. Is there somewhere I can find a list of common naming standards? Commented Jun 25, 2016 at 13:58
0

I always used to to the name_first order as it effectively groups the fields making intellisense easy to use.

However, it can get annoying when you are refactoring. eg:

iteration 1:

table person :
 firstName
 address

iteration 2:

table person
 firstName //todo:: change this everywhere to match the new scheme
 nameSecond
 address

Additionaly if you have many of these it suggests you may need more tables

table person
 nameId
table name
 id
 first
 last
 middle

Although obviously with the name example this is a bit overkill.

..thinking about it though, people can have n names maybe

table name
 personId
 type //first, middle, last, nickname etc 
 value

is better!!

answered Jun 25, 2016 at 10:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.