在SQL Server 2005中应该使用什么数据类型来存储电话号码? [英] What datatype should be used for storing phone numbers in SQL Server 2005?

查看:1405
本文介绍了在SQL Server 2005中应该使用什么数据类型来存储电话号码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将电话号码存储在表格中。请建议我应该使用哪种数据类型?
等等。请在回复之前阅读..

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 to be indexed heavily as Sales Reps can use this field for searching (including wild character search).

截至目前,我们预计电话号码会以多种格式出现(来自XML文件)。我是否必须编写解析器才能转换为统一格式?可能有数百万个数据(有重复数据),每次有些源数据通过时,我都不想占用服务器资源(在预处理过多等活动中)。

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..

欢迎任何建议..

更新:我无法控制源数据。只是xml文件的结构是标准的。希望将xml解析保持在最低限度。
一旦进入数据库,检索应该很快。这里有一个疯狂的建议是它甚至应该使用Ajax AutoComplete功能(因此Sales Reps可以立即看到匹配的功能)。 OMG !!

推荐答案

这包括:


  • 国际号码?

  • 扩展名?

  • 除了实际号码之外的其他信息(如请问bobby)?

如果所有这些都不是,我会使用10个char字段并删除所有非数字数据。如果第一个是yes而另外两个是no,我将使用两个varchar(50)字段,一个用于原始输入,另一个用于所有非数字数据条带化并用于索引。如果2或3是,我想我会做两个字段和某种疯狂的解析器来确定什么是扩展或其他数据并适当地处理它。当然,您可以通过对索引执行某些操作来避免第二列,在创建索引时它会删除多余的字符,但我只是制作第二列,并且可能会使用触发器删除字符。

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.

更新:为了解决AJAX问题,它可能没有您想象的那么糟糕。如果这是实际上对表进行任何操作的主要方式,则按照我的说法仅存储辅助列中的数字,然后使该列的索引成为聚簇索引。

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.

这篇关于在SQL Server 2005中应该使用什么数据类型来存储电话号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆