Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Column Names and Primary Keys

Status
Not open for further replies.

wallaceoc80

Programmer
Jul 7, 2004
182
GB
Is it wrong to have many different tables with a primary key of the same name and effectively they refer to the same number?

For example:

I have an APP table with primary key AppID.

I also have an AppContacts table with primary key AppID.

I also have a FAQ table with FaqID as the primary key and AppID as another column so that I can link these 2 tables.

The reason I have the same column names is because I need a way to link both tables. Can anybody see a problem with this?

Regards,

Wallace
 
Personally I only reuse a column name when the two columns will hold itentical data. Such as in the case of a PK and FK. I don't see any problem with using the AppID as the PK in your AppContacts table providing that AppID, as it relates to the AppContacts table, means the same thing as AppID , as it relates to the APP table. If they do not mean the same thing, then AppContacts.AppID should be renamed.

Denny

--Anything is possible. All it takes is a little research. (Me)
 
Nope, it is not wrong. Your example, AppID sounds decriptive enough to add clarity to the code. You will use the table name to provide the specific reference where requried, and I find using the same name where appropriate tends to make coding easier. But to use something like PK_ID everywhere would be confusing.

Richard
 
I would reuse the name to indicate a primary key froeign key relationship. I think it makes it easier for the developer to see the relationshsips when coding. However, I would not reuse the name if this relationship does not exist. Then it gets confusing. Suppose you had a customer table and a vendor table. I would not use CompanyID or PersonID for both, I would use CustomerID in one and VendorID in the other. The it is always clear which id is which. And if you ever need the customer and vendor information together inthe same query, you won't need to alias.

And I would never user any circumstances consider using just the word ID as the ID field as it is not descriptive enough.

Questions about posting. See faq183-874
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top