SQL Server 在表中查找字符串

来源:互联网 发布:江南网络教育 编辑:程序博客网 时间:2024/04/26 17:09

select convert(varchar(255),'') dsca
into #y
where 1=0

-- delete #y
declare @s varchar(255)
set @s='192.168.0.71'
DECLARE bbb cursor for
select  table_schema,TABLE_NAME,column_name  FROM information_schema.columns
    where table_name in (select  table_name from information_schema.tables where TABLE_type='BASE TABLE' and table_name like '%%' )
    and data_type like '%varchar%'

declare @sch varchar(255)
declare @t varchar(255)
declare @f varchar(255)
open bbb
fetch  next from bbb into @sch, @t,@f
while @@fetch_status=0
begin

exec( ' if exists (select * from '+ @sch + '.' + @t+' where '+@f+'='+''''+@s+''''+'  )  insert into #y select '+''''+@t+'.'+@f+''''  )

 

---------------------------下面放个类似的,删除所有表-------------------------------------

go
declare @tbname varchar(250)
declare #tb cursor for select name from sysobjects where objectproperty(id,'IsUserTable')=1
open #tb
fetch next from #tb into @tbname
while @@fetch_status=0
begin
  exec('drop table ['+@tbname+']')
  fetch next from #tb into @tbname
end
close #tb
deallocate #tb
原创粉丝点击