关于数据检索问题

Ray_Zhang 2009-04-24 05:14:46
我有一张保存客户信息的表,包含客户名称,地址,联系人等信息,
我有很多客户名称但名称都不全,要查找出其他信息
如果都用

NAME LIKE '%%' oR NAME LIKE '%%'
感觉慢,而且不便于管理,所以检索过的记录保存在另一张表中,有没有好的方法
...全文
63 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
htl258_Tony 2009-04-25
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 HEROWANG 的回复:]
SQL code试试全文索引

create table testIndex
(
id int identity(1,1) primary key,
nm varchar(100) unique not null,
sex varchar(10)
)
create UNIQUE index UQ__testIndex__0DAF0CB0
on testindex(nm)

insert into testindex
select 'aaabbb','m' union all
select 'bbb','w' union all
se…
[/Quote]
学习。。
-狙击手- 2009-04-25
  • 打赏
  • 举报
回复
ws_hgo 2009-04-25
  • 打赏
  • 举报
回复
你用
charindex试下
select * from tb where charindex('你要找的内容',Col1)>0


要不就用6楼的
sdhdy 2009-04-24
  • 打赏
  • 举报
回复
用charindex
select * from tb where charindex('你要找的内容',name)>0
  • 打赏
  • 举报
回复
试试全文索引

create table testIndex
(
id int identity(1,1) primary key,
nm varchar(100) unique not null,
sex varchar(10)
)
create UNIQUE index UQ__testIndex__0DAF0CB0
on testindex(nm)

insert into testindex
select 'aaabbb','m' union all
select 'bbb','w' union all
select 'ccc','w' union all
select 'ddd','m'


insert into testindex
select '麦蒂未伤愈中途退出训练复出时间再度成疑','北京'
go
--创建全文目录
sp_fulltext_catalog 'abc','create'
go
--创建全文索引(‘表名‘,’创建/删除‘,’全文目录名‘,’约束名‘)
sp_fulltext_table 'testindex','create','abc','UQ__testIndex__0DAF0CB0'
go
--添加列到全文索引(‘表名‘,’列名‘,’添加/删除‘)
sp_fulltext_column 'testindex','nm','add'

go
--建立全文索引
--activate,是激活表的全文检索能力,也就是在全文目录中注册该表
execute sp_fulltext_table 'testindex','activate'
go
--填充全文索引目录
execute sp_fulltext_catalog 'abc','start_full'
go

--检查全文目录填充情况
While fulltextcatalogproperty('abc','populateStatus')<>0
begin

--如果全文目录正处于填充状态,则等待30秒后再检测一次
waitfor delay '0:0:30'
end

--全文目录填充完成后,即可使用全文目录检索




SELECT * FROM testindex WHERE CONTAINS(nm, '麦蒂')

/*

id nm sex
----------- --------------------------------------------- ------------------------------------------------ ----------
5 麦蒂未伤愈中途退出训练复出时间再度成疑 北京

(所影响的行数为 1 行)
*/
insert into testindex
select '麦蒂未伤愈中途退出训练复出时间再度成疑12121','北京'
go
SELECT * FROM testindex WHERE CONTAINS(nm, '麦蒂')
-----No result
/*

id nm sex
----------- --------------------------------------------- ------------------------------------------------ ----------
5 麦蒂未伤愈中途退出训练复出时间再度成疑 北京

(所影响的行数为 1 行)
*/
go

--填充全文索引目录
execute sp_fulltext_catalog 'abc','start_full'
go
--检查全文目录填充情况
While fulltextcatalogproperty('abc','populateStatus')<>0
begin

--如果全文目录正处于填充状态,则等待30秒后再检测一次
waitfor delay '0:0:30'
end


SELECT * FROM testindex WHERE CONTAINS(nm, '麦蒂')

go
/*

id nm sex
----------- ---------------------------------------------------------------------------------------------------- ----------
6 麦蒂未伤愈中途退出训练复出时间再度成疑12121 北京
5 麦蒂未伤愈中途退出训练复出时间再度成疑 北京

(所影响的行数为 2 行)

*/
sp_fulltext_table 'testindex','drop'
go
sp_fulltext_catalog 'abc','drop'
go
drop table testIndex
billpu 2009-04-24
  • 打赏
  • 举报
回复
没看懂 找到所有信息不全的记录?还是信息全的记录?

如果是全的
select * from where nullif(name,'')+nullif(address,'')+... is not null
注意字段类型 如果类型不同用convert或cast转换

如果是不全的
select * from where nullif(name,'')+nullif(address,'')+... is null

rucypli 2009-04-24
  • 打赏
  • 举报
回复
NAME LIKE '%XX%' 不慢
usher_gml 2009-04-24
  • 打赏
  • 举报
回复
建索引...查询的话没太多办法(名称都不全)..
ojuju10 2009-04-24
  • 打赏
  • 举报
回复
数据量有多大,字段有多少?
mugua604 2009-04-24
  • 打赏
  • 举报
回复
全文索引??

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧