Data type for telephone numbers
Hey Jason, this is a very trivial question, but would you recommend storing telephone numbers as varchar?
This is a very subjective question. It's a difficult one in that to answer it in general terms requires me to mull over my mental collection of database heuristics, some of which seem to contradict each other. The easy answer is, "It depends." But if I'm forced to go one way or the other, here is my answer.
I generally use VARCHARs to store telephone numbers. Storage is not so expensive these days that I benefit that much from the savings found by storing them as numeric values. Also, I don't have to perform any numeric calculations on them, so I don't have to perform any type conversions.
If I store phone numbers as VARCHARs, I can also store formatting information such as dashes or parentheses. I can constrain the format with a check constraint like this:
create table MyTable ( Name varchar(50), Phone varchar(15) check (Phone like '(???)???-????') );This can be expanded to support international numbers. Also, storing phone numbers as VARCHARs, I can easily filter rows by using the LIKE operator. The same kind of operation with numeric data is possible, though more complicated.
For More Information
- What do you think about this answer? E-mail the edtiors at [email protected] with your feedback.
- The Best SQL Web Links: tips, tutorials, scripts, and more.
- Have an SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.