5

I read this tutorial, but I got confused about this.

What naming style should I be using in this case:

  • My table name: QuestionTypes or question_types?
  • My table id: QuestionTypeID or QuestionType_ID, question_type_id?

I know when MySQL workbench create .sql file, QuestionType_ID will be converted into questiontype_id, so should I be using this style: QuestionType?

Thank you very much.

NickD
  • 5,937
  • 1
  • 21
  • 38
Jack
  • 724
  • 1
  • 8
  • 15

2 Answers2

1

If you want to follow that specific convention, your table would be named question_types, and the field question_type_id.

I don't follow that convention, so I would name the table QuestionType and the field QuestionTypeId.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • but when MySQL workbench create sql file it convert QuestionType into questiontype, it make me confused – Jack Jun 12 '13 at 06:44
  • @Jack: That is just a choise that the author of that program has done. As long as the database treats the identifiers as case insensetive, it doesn't matter if you use `QuestionType` or `questiontype` (or `QuEsTiOnTyPe`) to use it, but that doesn't mean that you should change your convention for *naming* things. – Guffa Jun 12 '13 at 07:00
0

Technically if you are consistent with how you name things anything is good to go. There will be arguments on both sides on whether to use CamelCase or underscores.

I personally suggest naming your tables in singular (so question_type over question_types). It may seem trivial, but eventually you will run into situations where the pluralized version may introduce problems with spelling, or general consistency. That's part 1.

Columns should always be singular.

When I started working with databases, I went with the underscore method for names and for columns. Pretty sure I got the suggestion form SO, but I don't know for sure.

I also avoid the long names on the ID field because I find it spurious. My schemas are always pretty obvious (workbench or otherwise) and my queries always have the identification prefix, so the long name just increases the amount of characters I have to type, with no actual benefit of the added characters.

I seem to remember reading this thread to get a better idea of what method to use in the plural vs. singular tables. Hope it helps.

Table Naming Dilemma: Singular vs. Plural Names

Community
  • 1
  • 1
Jason St. Jacques
  • 383
  • 1
  • 3
  • 14