Ask the Expert

Varchar or number for better performance?

Which one is better for performance as unique index, varchar or number? I have peculiar requirements where my unique key is varchar(6) something like "006500," which is used in many other tables as foreign key. I was wondering which can give me better performance in this case -- defining one numeric unique ID number and using this as foreign key in other tables? Because in the last case i need to make two queries first to retrieve unique ID number and then on other table where it is foreign key to retrieve the value I need, while in the first case I can make query directly to the foreign key table.

    Requires Free Membership to View

In all my years of working with databases, I have never once worried about whether an index on VARCHAR2 or NUMBER columns performs better. If I have a number, and I will be performing some sort of numerical calculations on it, then I would never store this as a character string in the column. And unless I had a specific reason to do otherwise, I would store the value as a NUMBER datatype even if I am not performing calculations on it. Many times I have gone into database design thinking I was not going to perform calculations on a field and then had to change that idea in the future. I would store your data as a NUMBER because that is the proper datatype for the data. But I still am not thinking of performance reasons here. Any performance differences are likely to be so miniscule as to go unnoticed.

This was first published in August 2007

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
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
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: