sql 2000在数据库所有表的所有列中查找一个字符串
sql2000在数据库所有表的所有列中查找一个字符串比如“eyes”这个字符不知道在那个表的那一列里面怎么查询在那里麻烦帮我写一下语句...
sql 2000在数据库所有表的所有列中查找一个字符串
比如 “eyes”这个字符 不知道在那个表的那一列里面 怎么查询在那里
麻烦帮我写一下语句 展开
比如 “eyes”这个字符 不知道在那个表的那一列里面 怎么查询在那里
麻烦帮我写一下语句 展开
展开全部
create procedure Findeyes
as
declare @ls_tblname varchar(100)
declare @ls_colname varchar(100)
declare @ls_sql varchar(4000)
declare @li_count integer
create table #tmp_tbl1
(
exists_count integer
)
create table #result
(
tbl_name varchar(100),
col_name varchar(100)
)
declare c1 cursor for
select sysobjects.name as table_name,syscolumns.name as col_name from sysobjects a,syscolumns b where a.id = b.id and b.xtype in (35,99,167,231)
open c1
fetch c1 into @as_tblname,@as_colname
while 1 = 1 begin
if @@sqlstatus = 2 begin
break
end
select @ls_sql = "select count(1) from " + @as_tblname + "贺芦段 where " +@as_colname +" like '%eyes%'"
insert into #tmp_tbl1 exec @ls_sql --搜索含eyes的字段
select @li_count = exists_count from #tmp_tbl1
if @li_count > 0 begin
insert into #result select @as_tblname,@as_colname --把含有该字段的表和字段名插到临时表去
end
end
close c1
select tbl_name,col_name from #result order by tbl_name,col_name --把含有该字禅誉段的表和字段名选出来
执行这个 procedure 在查询分析器哗滚里:exec Findeyes
as
declare @ls_tblname varchar(100)
declare @ls_colname varchar(100)
declare @ls_sql varchar(4000)
declare @li_count integer
create table #tmp_tbl1
(
exists_count integer
)
create table #result
(
tbl_name varchar(100),
col_name varchar(100)
)
declare c1 cursor for
select sysobjects.name as table_name,syscolumns.name as col_name from sysobjects a,syscolumns b where a.id = b.id and b.xtype in (35,99,167,231)
open c1
fetch c1 into @as_tblname,@as_colname
while 1 = 1 begin
if @@sqlstatus = 2 begin
break
end
select @ls_sql = "select count(1) from " + @as_tblname + "贺芦段 where " +@as_colname +" like '%eyes%'"
insert into #tmp_tbl1 exec @ls_sql --搜索含eyes的字段
select @li_count = exists_count from #tmp_tbl1
if @li_count > 0 begin
insert into #result select @as_tblname,@as_colname --把含有该字段的表和字段名插到临时表去
end
end
close c1
select tbl_name,col_name from #result order by tbl_name,col_name --把含有该字禅誉段的表和字段名选出来
执行这个 procedure 在查询分析器哗滚里:exec Findeyes
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询