What datatype should be used for storing phone numbers in SQL Server 2005?

前端 未结 16 1958
情话喂你
情话喂你 2020-11-28 05:29

I need to store phone numbers in a table. Please suggest which datatype should I use? Wait. Please read on before you hit reply..

This field needs

相关标签:
16条回答
  • 2020-11-28 05:33

    I realize this thread is old, but it's worth mentioning an advantage of storing as a numeric type for formatting purposes, specifically in .NET framework.

    IE

    .DefaultCellStyle.Format = "(###)###-####" // Will not work on a string
    
    0 讨论(0)
  • 2020-11-28 05:34

    I would use a varchar(22). Big enough to hold a north american phone number with extension. You would want to strip out all the nasty '(', ')', '-' characters, or just parse them all into one uniform format.

    Alex

    0 讨论(0)
  • 2020-11-28 05:38

    nvarchar with preprocessing to standardize them as much as possible. You'll probably want to extract extensions and store them in another field.

    0 讨论(0)
  • 2020-11-28 05:40

    Normalise the data then store as a varchar. Normalising could be tricky.

    That should be a one-time hit. Then as a new record comes in, you're comparing it to normalised data. Should be very fast.

    0 讨论(0)
  • 2020-11-28 05:43

    I'm probably missing the obvious here, but wouldn't a varchar just long enough for your longest expected phone number work well?

    If I am missing something obvious, I'd love it if someone would point it out...

    0 讨论(0)
  • 2020-11-28 05:45

    We use varchar(15) and certainly index on that field.

    The reason being is that International standards can support up to 15 digits

    Wikipedia - Telephone Number Formats

    If you do support International numbers, I recommend the separate storage of a World Zone Code or Country Code to better filter queries by so that you do not find yourself parsing and checking the length of your phone number fields to limit the returned calls to USA for example

    0 讨论(0)
提交回复
热议问题