August 29, 2012 at 9:32 am
hi
i need to craete table which has phone number field,
format (345) 234 - 2345
what is the best data type i can use,int,varchar.
plz suggest me
August 29, 2012 at 9:43 am
It should be char or varchar.
Ideally you should only store the digits and format the phone in the front end. However, you'll need an extra field for extension if needed.
August 29, 2012 at 9:44 am
Numeric datatypes are inappropriate because telephone numbers may have embedded spaces, non-numeric characters and leading zero's. Length isn't constant either, so most folks use VARCHAR.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
August 29, 2012 at 10:31 am
Luis Cazares (8/29/2012)
It should be char or varchar.Ideally you should only store the digits and format the phone in the front end. However, you'll need an extra field for extension if needed.
I can imagine international numbers introducing difficulties to this solution (different display formats, therefore need to parse the country code first in a separate column etc etc).
I'd stick with varchar & use suitable constraints and front-end validation to stop rubbish getting in there.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
August 29, 2012 at 12:01 pm
Luis Cazares (8/29/2012)
It should be char or varchar.Ideally you should only store the digits and format the phone in the front end. However, you'll need an extra field for extension if needed.
This. Believe me, you will be much happier writing code going forward when all you have to deal with is xxxxxxxxxx.
August 29, 2012 at 12:14 pm
Phil Parkin (8/29/2012)
Luis Cazares (8/29/2012)
It should be char or varchar.Ideally you should only store the digits and format the phone in the front end. However, you'll need an extra field for extension if needed.
I can imagine international numbers introducing difficulties to this solution (different display formats, therefore need to parse the country code first in a separate column etc etc).
I'd stick with varchar & use suitable constraints and front-end validation to stop rubbish getting in there.
Display format should be defined for each user, not each phone. If managing international numbers, there should be a column designed for it. I'll prefer to store just the digits and probably in separate fields (according to the different attributes) to allow easy formatting. For me a phone number could be a composite attribute or even an entity, however it can be handled as a simple attribute.
August 29, 2012 at 6:43 pm
In my shop we store the 10 digit us number as a VARCHAR(16) (to allow for international numbers) but do not store any country code information or formating with the phone number (xxxxxxxxxx). we look up the country code based on other information in the database.
For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]
Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
Jeff Moden's Cross tab and Pivots Part 1[/url]
Jeff Moden's Cross tab and Pivots Part 2[/url]
August 29, 2012 at 11:16 pm
harri.reddy (8/29/2012)
hii need to craete table which has phone number field,
format (345) 234 - 2345
what is the best data type i can use,int,varchar.
plz suggest me
I have to chime in with several of the others. Don't store formatted telephone numbers in the database. Do the formatting in the front end if you have one.
A better thing to do would be to break the phone number up into pieces for Area Code, Exchange, and Line Number. Of course, international numbers will require country code (1-3 digits), city code (0 to 4 digits), and line number (1 to 6 digits, IIRC). Well, except for Mexico which uses country code, band, and some other stuff.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 29, 2012 at 11:55 pm
Use varchar . and don't save the formatted data in the database.
I had faced this issue , and it was a hell of a mess when a new company was acquired and we started using the data of their end. Format of phone number may differ based on the area or region or company, and you might loose flexibility.
why varchar ? I think it's better to do string operations on varchar in sql.
~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one :ermm:
August 30, 2012 at 7:19 am
I guess if you absolutely must store a formatted phone number you could use a computed column.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply