在 SQL Server 2005 中应该使用什么数据类型来存储电话号码?

2021-12-21 00:00:00 indexing sql-server

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

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 功能一起使用(这样销售代表可以立即看到匹配的).天啊!!

推荐答案

是否包括:

  • 国际号码?
  • 扩展?
  • 除了实际数字之外的其他信息(例如要鲍比")?

如果所有这些都不是,我将使用 10 个字符的字段并去除所有非数字数据.如果第一个是肯定的,其他两个不是,我会使用两个 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.

相关文章