本文介绍了数据库设计-主键命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道人们如何(为什么)以下3种不同的约定来命名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?

-示例1-

表名:用户,
主键列名称:user_id

Table name: User,
Primary key column name: user_id

-示例2-

表名:用户,
主键列名称:id

Table name: User,
Primary key column name: id

-示例3-

表名:用户,
主键列名称:pk_user_id

Table name: User,
Primary key column name: pk_user_id

只想听听想法,也许在此过程中学到一些东西:)

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

谢谢.

推荐答案

我会选择选项2.对我来说,"id"本身似乎就足够了.由于该表是用户,因此用户"中的"id"列表示这是用户的标识标准.

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.

这篇关于数据库设计-主键命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 03:34