在我们的开发团队中,我们就主键和外键的命名约定展开了激烈的辩论.我们小组基本上有两个学派:
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 PersonAge
或 PersonGender
is. I ask him what his Age is.
就像我说的,这是一场激烈的辩论,我们一直在讨论这个问题.我有兴趣了解一些新的观点.