In our development team, we have a debate over the naming convention for primary and foreign keys. There are basically two schools of thought in our group:
one:
Primary Table (Employee) Primary Key is called ID Foreign table (Event) Foreign key is called EmployeeID
or
2:
Primary Table (Employee) Primary Key is called EmployeeID Foreign table (Event) Foreign key is called EmployeeID
I prefer not to duplicate the table name in any column (so I prefer option 1 above). Conceptually, this is consistent with many recommended practices in other languages, where you do not use the name of an object in its property names. I think that naming the foreign key EmployeeID (or Employee_ID could be better) tells the reader that this is the Employee table ID column.
Some others prefer option 2, in which you specify a primary key with a table name prefix so that the column name is the same throughout the database. I see this, but now you cannot visually distinguish the primary key from the foreign key.
In addition, I consider it redundant to have the table name in the column name, because if you consider the table as an entity and the column as a property or attribute of this object, you consider this attribute to be an attribute of the Employee , not the EmployeeID employee. I do not ask my colleague what his PersonAge or PersonGender . I ask him what his age is.
So, as I said, this is a heated debate, and we go on and on. I am interested in getting new perspectives.
sql naming-conventions database-design
Jeremy Sep 02 '09 at 19:13 2009-09-02 19:13
source share