sql 全站搜索
SQL全站搜索
Full_Search(@string varchar(50))
as
begin
declare @tbname
varchar(50)
declare tbroy cursor for select name from sysobjects
where
xtype= 'u ' --第一个游标遍历所有的表
open tbroy
fetch next from tbroy into
@tbname
while @@fetch_status=0
begin
declare @colname
varchar(50)
declare colroy cursor for select name from syscolumns
where
id=object_id(@tbname) and xtype in (
select xtype from systypes
where
name in ( 'varchar ', 'nvarchar ', 'char ', 'nchar ') --数据类型为字符型的字段
)
--第二个游标是第一个游标的嵌套游标,遍历某个表的所有字段
open colroy
fetch next from colroy
into @colname
while @@fetch_status=0
begin
declare @sql
nvarchar(1000),@j int
select @sql= 'select @i=count(1) from ' +@tbname + '
where '+ @colname+ ' like '+ '''%'+@string+ '%'''
exec sp_executesql
@sql,N'@i int output',@i=@j output --输出满足条件表的记录数
if @j> 0
BEGIN
select 包含字串的表名=@tbname
--exec( 'select distinct '+@colname+' from '
+@tbname + ' where '+ @colname+ ' like '+ '''%'+@string+ '%''')
END
fetch next from colroy into @colname
end
close colroy
deallocate colroy
fetch next from tbroy into @tbname
end
close tbroy
deallocate tbroy
end
go
exec Full_Search
'搜索关键字'
最新文章
- React Native环境配置和简单使用
- webDriver环境搭建与测试
- php 接收表单 方法的区别
- thinkphp 常用
- vi编辑器基本用法介绍
- cf754D
- C#递归搜索指定目录下的文件或目录
- http-关于application/x-www-form-urlencoded等字符编码的解释说明
- CentOS6.9中挂载NTFS移动硬盘
- 【MyBatis源码分析】插件实现原理
- Web项目中手机注册短信验证码实现的全流程及代码
- python 加密算法及其相关模块的学习(hashlib,random,string,math)
- asp.net mvc 通过StyleBundle添加样式后,没有作用
- cp备份操作时如何忽略指定的目录
- Matplotlib新手上路(下)
- Unity Shader入门精要之 screen post-processing effect
- Linux下SVN配置hook经验总结
- 【运维理论】RAID级别简介
- sed删除空行和开头的空格和tab键
- jdk版本对应数字
热门文章
- [bzoj2431][HAOI2009][逆序对数列] (dp计数)
- noip模拟赛 读
- Spring + quartz实现定时发送邮件功能
- 微软消息队列MessageQueue(MQ)
- CI 日志类
- cisco路由器上的DHCP
- [JavaEE] Testing the Java EE Application : Basic Arquillian integration test
- Android天气预报+百度天气接口
- 开发汉澳sinox64位,对接汉澳矩阵电脑
- ZOJ2599:Graduated Lexicographical Ordering(很经典的数位DP)