dbTalk Databases Forums  

Linked Field Names

comp.databases comp.databases


Discuss Linked Field Names in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
filipe.martins.10@gmail.com
 
Posts: n/a

Default Linked Field Names - 09-12-2007 , 02:52 AM






Hello.
What's the recommended way for naming linked field?
For example, if we have an employee table, being the "EmployeeId"
field the primary key, shouldn't all other tables that reference an
employee have a "EmployeeId" field as a foreign key?

I really think so. Can't see any advantage in not doing so, and many
disadvantages in not sticking to this convention. But I've seen so
many people disagreeing that I want to hear from you all.

Thanks.


Filipe Martins
http://www.i-senso.com


Reply With Quote
  #2  
Old   
Carl Kayser
 
Posts: n/a

Default Re: Linked Field Names - 09-12-2007 , 04:41 AM







<filipe.martins.10 (AT) gmail (DOT) com> wrote

Quote:
Hello.
What's the recommended way for naming linked field?
For example, if we have an employee table, being the "EmployeeId"
field the primary key, shouldn't all other tables that reference an
employee have a "EmployeeId" field as a foreign key?

I really think so. Can't see any advantage in not doing so, and many
disadvantages in not sticking to this convention. But I've seen so
many people disagreeing that I want to hear from you all.

Thanks.


Filipe Martins
http://www.i-senso.com

I'm surprised that you see many people disagreeing with this convention.
It's pretty standard to use data dictionaries in the software industry so
that the data elements are well defined. Note that there can be some
exceptions. If your employee table includes both the employee and his
manager which column is the EmployeeID? The answer is obvious but whatever
name you make for the manager column it represents another EmployeeID value
(except when the employee is the company president).




Reply With Quote
  #3  
Old   
Axel Hallez
 
Posts: n/a

Default Re: Linked Field Names - 09-12-2007 , 05:05 AM



filipe.martins.10 (AT) gmail (DOT) com wrote:
Quote:
Hello.
What's the recommended way for naming linked field?
For example, if we have an employee table, being the "EmployeeId"
field the primary key, shouldn't all other tables that reference an
employee have a "EmployeeId" field as a foreign key?

I really think so. Can't see any advantage in not doing so, and many
disadvantages in not sticking to this convention. But I've seen so
many people disagreeing that I want to hear from you all.

Thanks.


Filipe Martins
http://www.i-senso.com

There are IMO two aspects about naming foreign key attributes.
You want to make it clear what you are referring to, so using the same
name as the attribute you refer to is good for that.
However you also want it to be clear what the foreign key attribute is
used for. In many cases this should not be a problem, but there are
cases where the role of foreign key attribute is ambiguous. This is
especially true if one table contains several foreign keys referring to
the same primary key.

Axel Hallez


Reply With Quote
  #4  
Old   
David Cressey
 
Posts: n/a

Default Re: Linked Field Names - 09-12-2007 , 08:21 AM




<filipe.martins.10 (AT) gmail (DOT) com> wrote

Quote:
Hello.
What's the recommended way for naming linked field?
For example, if we have an employee table, being the "EmployeeId"
field the primary key, shouldn't all other tables that reference an
employee have a "EmployeeId" field as a foreign key?

I really think so. Can't see any advantage in not doing so, and many
disadvantages in not sticking to this convention. But I've seen so
many people disagreeing that I want to hear from you all.

Thanks.

I see your question as containing two issues: the first is concerning
artificial keys like EmployeeId. The second is with regard to always using
the same key to reference a given table.

With regard to the first issue: EmployeeId, a number that uniquely
identifies an employee, is an artificial key. That's beyond doubt. Beyond
that, the question might be, who assigns an EmployeeId to a new employee?
In many cases, it's HR. During the employee's first day on the job, they
take a photo, transfer the photo to the new employee's badge, and also
print the Employee Number (or employeeid if you prefer) on that badge,
marking the connection between that Id and that employee.

Numbers are both more efficient and more effective for the purpose of
uniquely identifying employees than any natural key such as name might be.
They are also preferable, in some ways, to some other ID like Social
Security Number(SSN) in the US. This is extensively written up in the
fundamentals of databases, which I refer you to.

Another question might be whether it's HR or IT that ultimately assigns the
"next available number" to the "next incoming employee". That's a whole big
can of worms that I don't want to touch right now.

Next, in the case of an employee table, it's possible that there is more
than one candidate key. For example, EmployeeId and SSN. The question
might be whether it's better to always link a table reference via the same
key or whether it's better to use employeeId for some references and SSN for
others. In general, data management will be simpler and easier if all
references use the same key, the one designated "primary key". It should
be noted that which of several candidate keys is called "primary" is an
arbitrary choice.

There are cases where SSN might profitably be used. For example, if we
have a table that contains entries for both employees and prospective
employees, it might be desirable to use SSN to identify such people, and
that could serve as a reference to a person of either kind.

There are performance implications to all of this, but that's secondary to
the fundamentals of data management, to which I refer you again.







Reply With Quote
  #5  
Old   
--CELKO--
 
Posts: n/a

Default Re: Linked Field Names - 09-16-2007 , 12:43 AM



Quote:
What's the recommended way for naming linked [sic: links are not references] field [sic: fields are not columns] ?
Please read a book on RDBMS so you now the concepts.

Quote:
For example, if we have an employee [sic: Personnel, not the name of a singleset element] table, being the "employee_Id" field [fields are not columns] the primary key, shouldn't all other tables that reference an employee have a "EmployeeId" field [sic] as a foreign key?
Yes. One identifier, one place, one time, the references to it.
Please, please read at least one book on the basics of RDBMS.





Reply With Quote
  #6  
Old   
Gints Plivna
 
Posts: n/a

Default Re: Linked Field Names - 09-27-2007 , 08:04 AM



On 12 Sept., 10:52, filipe.martins... (AT) gmail (DOT) com wrote:
Quote:
Hello.
What's the recommended way for naming linked field?
For example, if we have an employee table, being the "EmployeeId"
field the primary key, shouldn't all other tables that reference an
employee have a "EmployeeId" field as a foreign key?

I really think so. Can't see any advantage in not doing so, and many
disadvantages in not sticking to this convention. But I've seen so
many people disagreeing that I want to hear from you all.

Thanks.

Filipe Martinshttp://www.i-senso.com
If you are speaking only about naming conventions then my version of
them you can found here
Naming conventions of tables, columns, indexes, keys, sequences in
Oracle at http://www.gplivna.eu/papers/naming_conventions.htm

It includes also how to name foreign key columns as well as the very
foreign key constraints.

Gints Plivna
http://www.gplivna.eu



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.