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

<p>This field needs to be indexed heavily as Sales Reps can use this field for searching (including wild character search).</p>

<p>As of now, we are expecting phone numbers to come in a number of formats (from an XML file). Do I have to write a parser to convert to a uniform format? There could be millions of data (with duplicates) and I dont want to tie up the server resources (in activities like preprocessing too much) every time some source data comes through..</p>

<p>Any suggestions are welcome..</p>

<p>Update: <strong>I have no control over source data. Just that the structure of xml file is standard. Would like to keep the xml parsing to a minimum.
Once it is in database, retrieval should be quick. One crazy suggestion going on around here is that it should even work with Ajax AutoComplete feature (so Sales Reps can see the matching ones immediately). OMG!!</strong></p>

[{'answer_id': 75113, 'author': 'John Sheehan', 'author_id': 1786, 'author_profile': 'https://Stackoverflow.com/users/1786', 'pm_score': 2, 'selected': False, 'text': "<p>nvarchar with preprocessing to standardize them as much as possible. You'll probably want to extract extensions and store them in another field.</p>\n"}, {'answer_id': 75119, 'author': 'Iain Holder', 'author_id': 1122, 'author_profile': 'https://Stackoverflow.com/users/1122', 'pm_score': 1, 'selected': False, 'text': "<p>Normalise the data then store as a varchar.  Normalising could be tricky.</p>\n\n<p>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.</p>\n"}, {'answer_id': 75122, 'author': 'cori', 'author_id': 8151, 'author_profile': 'https://Stackoverflow.com/users/8151', 'pm_score': 2, 'selected': False, 'text': "<p>I'm probably missing the obvious here, but wouldn't a varchar just long enough for your longest expected phone number work well?</p>\n\n<p>If I <em>am</em> missing something obvious, I'd love it if someone would point it out...</p>\n"}, {'answer_id': 75125, 'author': 'user13270', 'author_id': 13270, 'author_profile': 'https://Stackoverflow.com/users/13270', 'pm_score': 1, 'selected': False, 'text': '<p>Use a <code>varchar</code> field with a length restriction.</p>\n'}, {'answer_id': 75130, 'author': 'Alex Fort', 'author_id': 12624, 'author_profile': 'https://Stackoverflow.com/users/12624', 'pm_score': 2, 'selected': False, 'text': "<p>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.</p>\n\n<p>Alex</p>\n"}, {'answer_id': 75136, 'author': 'Joseph Bui', 'author_id': 3275, 'author_profile': 'https://Stackoverflow.com/users/3275', 'pm_score': 3, 'selected': False, 'text': '<p>Use CHAR(10) if you are storing US Phone numbers only. Remove everything but the digits.</p>\n'}, {'answer_id': 75143, 'author': 'Joseph Daigle', 'author_id': 507, 'author_profile': 'https://Stackoverflow.com/users/507', 'pm_score': 2, 'selected': False, 'text': '<p>SQL Server 2005 is pretty well optimized for substring queries for text in indexed varchar fields. For 2005 they introduced new statistics to the string summary for index fields. This helps significantly with full text searching.</p>\n'}, {'answer_id': 75155, 'author': 'Kearns', 'author_id': 6500, 'author_profile': 'https://Stackoverflow.com/users/6500', 'pm_score': 7, 'selected': True, 'text': '<p>Does this include:</p>\n\n<ul>\n<li>International numbers?</li>\n<li>Extensions?</li>\n<li>Other information besides the actual number (like "ask for bobby")?</li>\n</ul>\n\n<p>If all of these are no, I would use a 10 char field and strip out all non-numeric data. If the first is a yes and the other two are no, I\'d use two varchar(50) fields, one for the original input and one with all non-numeric data striped and used for indexing. If 2 or 3 are yes, I think I\'d do two fields and some kind of crazy parser to determine what is extension or other data and deal with it appropriately. Of course you could avoid the 2nd column by doing something with the index where it strips out the extra characters when creating the index, but I\'d just make a second column and probably do the stripping of characters with a trigger.</p>\n\n<p>Update: to address the AJAX issue, it may not be as bad as you think. If this is realistically the main way anything is done to the table, store only the digits in a secondary column as I said, and then make the index for that column the clustered one.</p>\n'}, {'answer_id': 75163, 'author': 'Brad Osterloo', 'author_id': 9162, 'author_profile': 'https://Stackoverflow.com/users/9162', 'pm_score': 6, 'selected': False, 'text': '<p>We use varchar(15) and certainly index on that field.</p>\n\n<p>The reason being is that International standards can support up to 15 digits</p>\n\n<p><a href="http://en.wikipedia.org/wiki/Phone_number" rel="noreferrer">Wikipedia - Telephone Number Formats</a></p>\n\n<p>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</p>\n'}, {'answer_id': 75197, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>Since you need to accommodate many different phone number formats (and probably include things like extensions etc.) it may make the most sense to just treat it as you would any other varchar. If you could control the input, you could take a number of approaches to make the data more useful, but it doesn't sound that way. </p>\n\n<p>Once you decide to simply treat it as any other string, you can focus on overcoming the inevitable issues regarding bad data, mysterious phone number formating and whatever else will pop up. The challenge will be in building a good search strategy for the data and not how you store it in my opinion. It's always a difficult task having to deal with a large pile of data which you had no control over collecting.</p>\n"}, {'answer_id': 75239, 'author': 'Magnus Johansson', 'author_id': 3584, 'author_profile': 'https://Stackoverflow.com/users/3584', 'pm_score': 1, 'selected': False, 'text': "<p>Use SSIS to extract and process the information. That way you will have the processing of the XML files separated from SQL Server. You can also do the SSIS transformations on a separate server if needed. Store the phone numbers in a standard format using VARCHAR. NVARCHAR would be unnecessary since we are talking about numbers and maybe a couple of other chars, like '+', ' ', '(', ')' and '-'.</p>\n"}, {'answer_id': 5872451, 'author': 'fjleon', 'author_id': 455003, 'author_profile': 'https://Stackoverflow.com/users/455003', 'pm_score': 2, 'selected': False, 'text': '<p>using varchar is pretty inefficient. use the money type and create a user declared type "phonenumber" out of it, and create a rule to only allow positive numbers.</p>\n\n<p>if you declare it as (19,4) you can even store a 4 digit extension and be big enough for international numbers, and only takes 9 bytes of storage. Also, indexes are speedy.</p>\n'}, {'answer_id': 17784147, 'author': 'Rob G', 'author_id': 2097355, 'author_profile': 'https://Stackoverflow.com/users/2097355', 'pm_score': 1, 'selected': False, 'text': '<p>It is fairly common to use an "x" or "ext" to indicate extensions, so allow 15 characters (for full international support) plus 3 (for "ext") plus 4 (for the extension itself) giving a total of 22 characters. That should keep you safe.</p>\n\n<p>Alternatively, normalise on input so any "ext" gets translated to "x", giving a maximum of 20.</p>\n'}, {'answer_id': 42965499, 'author': 'Mr. Tripodi', 'author_id': 4220094, 'author_profile': 'https://Stackoverflow.com/users/4220094', 'pm_score': 1, 'selected': False, 'text': '<p>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.</p>\n\n<p>IE</p>\n\n<pre><code>.DefaultCellStyle.Format = "(###)###-####" // Will not work on a string\n</code></pre>\n'}, {'answer_id': 45651436, 'author': 'Jayghosh Wankar', 'author_id': 7173263, 'author_profile': 'https://Stackoverflow.com/users/7173263', 'pm_score': 1, 'selected': False, 'text': '<p><strong>It is always better to have separate tables for multi valued attributes like phone number.</strong></p>\n\n<p>As you have no control on source data so, you can parse the data from XML file and convert it into the proper format so that there will not be any issue with formats of a particular country and store it in a separate table so that <strong>indexing and retrieval both will be efficient</strong>.</p>\n\n<p>Thank you.</p>\n'}, {'answer_id': 61000613, 'author': 'Ej Manalo Carbona', 'author_id': 9160045, 'author_profile': 'https://Stackoverflow.com/users/9160045', 'pm_score': 0, 'selected': False, 'text': '<p>Use data type long instead.. dont use int because it only allows whole numbers between -32,768 and 32,767 but if you use long data type you can insert numbers between -2,147,483,648 and 2,147,483,647.</p>\n'}]
['https://Stackoverflow.com/questions/75105', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13205/']