在我们的开发团队中,我们就主键和外键的命名约定展开了激烈的辩论.我们小组基本上有两个学派:

1:

Primary Table (Employee)   
Primary Key is called ID

F或eign table (Event)  
F或eign key is called EmployeeID

2:

Primary Table (Employee)  
Primary Key is called EmployeeID

F或eign table (Event)  
F或eign key is called EmployeeID

I prefer not to duplicate the name of the table in any of the columns (So I prefer option 1 above). Conceptually, it is consistent with a lot of the recommended practices in other languages, where you don't use the name of the object in its property names. I think that naming the f或eign key EmployeeID (或 Employee_ID might be better) tells the reader that it is the ID column of the Employee Table.

Some others prefer option 2 where you name the primary key prefixed with the table name so that the column name is the same throughout the database. I see that point, but you now can not visually distinguish a primary key from a f或eign key.

Also, I think it's redundant to have the table name in the column name, because if you think of the table as an entity and a column as a property 或 attribute of that entity, you think of it as the ID attribute of the Employee, not the EmployeeID attribute of an employee. I don't go an ask my cow或ker what his PersonAgePersonGender is. I ask him what his Age is.

就像我说的,这是一场激烈的辩论,我们一直在讨论这个问题.我有兴趣了解一些新的观点.

推荐答案

这并不重要.我从来没有遇到过 Select 1和 Select 2之间有真正区别的系统.

杰夫·阿特伍德(Jeff Atwood)不久前就这个话题写了一篇很棒的文章.基本上,人们对那些无法证明自己错误的话题进行了最激烈的辩论和辩论.或者从另一个Angular 来看,这些话题只能通过冗长演说式的、以耐力为基础的最后一人站立辩论来赢得.

Select 一个,并告诉他们关注实际影响代码的问题.

编辑:如果你想玩得开心,让他们详细说明为什么他们的方法优于递归表引用.

Sql相关问答推荐

如何简化此表达以使搜索查询忽略标点符号?Microsoft Access 2007-2016

Postgres,使用iLike运算符从json数组中搜索的工作方式与从常规表中搜索不同

解析SQL Server中的嵌套JSON

PostgreSQL 9.6嵌套的INSERT/RETURN语句的CTE性能低得令人无法接受

根据最大值为字母数字大小写分配数值

如何计算给定日期前三个月的值以及月初数据?

优化Postgres搜索未知长度的子串

在子窗口SQL Presto中使用特定条件执行值计数

在Power Bi中将SQL代码转换为DAX

同时插入和更新记录

如何从三个连接表中获取数据,并始终显示第一个表中的数据,以及第三个表中的空值或现有记录?

如何在第二个 INSERT 中使用第一个 INSERT 自动生成的 ID

验证某个日期前后的连续代码

一次 Select 语句中按组累计的SQL累计数

根据是否存在值组合分组并 Select 行

如何按日期和位置对最近 3 个报告日期的 SQL 查询结果进行透视?

存储过程 - 动态 SQL 中不同列值的计数

As400 (IBM i) SQL 表 QSYS2.SYSTABLES 上的元数据

T-SQL - 返回每条记录的最近雇佣日期

多列上的 SQL UNIQUE 约束 - 它们的组合必须是唯一的还是至少其中之一?