Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database design - primary key naming conventions

Tags:

database

mysql

I am interested to know what people think about (AND WHY) the following 3 different conventions for naming database table primary keys in MySQL?

-Example 1-

Table name: User,
Primary key column name: user_id

-Example 2-

Table name: User,
Primary key column name: id

-Example 3-

Table name: User,
Primary key column name: pk_user_id

Just want to hear ideas and perhaps learn something in the process :)

Thanks.

like image 227
Mark Blades Avatar asked Oct 14 '10 13:10

Mark Blades


1 Answers

I would go with option 2. To me, "id" itself seems sufficient enough. Since the table is User so the column "id" within "user" indicates that it is the identification criteria for User.

However, i must add that naming conventions are all about consistency. There is usually no right / wrong as long as there is a consistent pattern and it is applied across the application, thats probably the more important factor in how effective the naming conventions will be and how far they go towards making the application easier to understand and hence maintain.

like image 60
Jagmag Avatar answered Sep 22 '22 00:09

Jagmag