Q
Problem solve Get help with specific problems with your technologies, process and projects.

Integer or CHAR(1) primary key?

I have a table containing customers and an additional table defining types of customers. There's a relationship between them defining the types of customers but integer type PK/FK for CUSTOMERS_TYPES/CUSTOMERS is used. Is it clever to use CHAR(1) PK instead of integer?

I have a table CUSTOMERS containing customers and an additional table defining types of customers (with only two...

records, Business and Residential). There's a relationship between them defining the types of customers but integer type PK/FK for CUSTOMERS_TYPES/CUSTOMERS is used. Is it clever to use CHAR(1) PK instead of integer (e.g., "B" and "R" instead of 1 and 2)?

Moreover, when I list my customers it is clear enough to present to users only "R" and "B" (FK fields) instead of making an additional join to retrieve real customer type names?

For your example, I would definitely use the CHAR(1) primary key. That is, assuming you are certain there will be only the two values. If it should happen that you need a third, be sure to choose a different letter. There is no good reason to use an integer key here, when the letters B and R have the added advantage that you will not need to do the join in most of your queries. Good call.

This was last published in July 2005

Dig Deeper on Oracle and SQL

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close