MS SQL SERVER 全库搜索
发布时间:2021-01-14 02:01:04 所属栏目:MySql教程 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 create proc global_search@key varchar(2000)asdeclare tab_cursor cursor for select name from sysobjects where type = 'U'declare @sql nvarchar
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 create proc global_search @key varchar(2000) as declare tab_cursor cursor for select name from sysobjects where type = 'U' declare @sql nvarchar(2000) declare @tab_name nvarchar(100) declare @col_name nvarchar(100) declare @row_count int open tab_cursor fetch next from tab_cursor into @tab_name while(@@fetch_status = 0) begin declare col_cursor cursor for select name from syscolumns where id = OBJECT_ID(@tab_name) and xtype = 167 open col_cursor fetch next from col_cursor into @col_name while(@@fetch_status = 0) begin set @sql = 'declare row_cursor cursor for select count(*) from ' + @tab_name + ' where ' + @col_name + ' like ''%' + @key + '%''' exec(@sql) open row_cursor fetch next from row_cursor into @row_count if @row_count > 0 print @tab_name + '.' + @col_name close row_cursor deallocate row_cursor fetch next from col_cursor into @col_name end close col_cursor deallocate col_cursor fetch next from tab_cursor into @tab_name end close tab_cursor deallocate tab_cursor 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:威海站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |