create table test(id int identity(1,1),content text)
insert test values('asdfsdfasdfsadfsdjflk大力sdjflkasjdf;lasdjf;lafsd')
insert test values('fdsgdsfgdfgsdfghrtjtyjkhkhjkhjljk大力ljk;jk;kl;kl;kl;')
go
create proc 替换
@s_str varchar(100),
@d_str varchar(100)
as
declare @id int
declare #tb cursor for select id from test
open #tb
fetch next from #tb into @id
while @@fetch_status=0
begin
declare @p varbinary(16),@postion int,@rplen int
select @p=textptr(CONTENT),@rplen=len(@s_str),@postion=charindex(@s_str,CONTENT)-1 from test where id=@id
while @postion>0
begin
updatetext test.CONTENT @p @postion @rplen @d_str
select @postion=charindex(@s_str,content)-1 from test where id=@id
end
fetch next from #tb into @id
end
close #tb
deallocate #tb
go
3、建立环境
打开查询分析器-->执行下列脚本:
--------------------------------------------
create database test ---创建test数据库
use test ---选择test数据库
create table dali (ID int not null primary key,MyImage image,FileType varchar(255),FileNmae varchar(255)) ---创建dali表
--dali表中 Id,MyImage,FileType 三列是必须的,因为要对image列索引的话,必须要有一个主键列,一个image列,一个存放文件类型的列
--我们知道在windows系统中文件类型是靠扩展名来区分的所以FileType列也就是用来放 文件的扩展名
--------------------------------------------
declare @Key sysname ; select @Key=c.name from syscolumns a,sysconstraints b,sysobjects c where a.id=object_id('a') and a.name='a' and a.id=b.id and b.constid=c.id and c.name like 'PK%'
exec sp_fulltext_table 'dali','create','My_FullDir',@Key ----这两句是为全文索引,对表进行标记