时间:2021-07-01 10:21:17 帮助过:26人阅读
添加架构支持后,虽偶尔会有报错,可查询架构:
declare @str nvarchar(10) declare @schemasname varchar(50) declare @tablename varchar(50) declare @colname varchar(50) declare @counts int declare @sql nvarchar(2000)--以上定义变量 declare cur1 cursor for select s.name schemasname,a.name tablename,B.name colname from sys.objects a,syscolumns b,sys.schemas s where a.object_id=b.id and a.schema_id=s.schema_id and a.type_desc=‘USER_TABLE‘--定义游标 set @str=‘污染‘ --设置要查找的字符 Open cur1 --打开游标 Fetch next From cur1 Into @schemasname,@tablename,@colname While(@@Fetch_Status = 0) --循环 Begin set @sql=N‘select @counts=COUNT(*) from ‘ + @schemasname + ‘.‘+ @tablename + ‘ where charindex(‘‘‘+@str+‘‘‘,‘+@colname+‘)>0‘ exec sp_executesql @sql,N‘@counts int output‘,@counts output --执行动态sql if @counts>0 --判断某个表某个字段是否存在特定字符 begin print @schemasname+‘,‘+@tablename+‘,‘+@colname --打印表名及字段名 end Fetch next From cur1 Into @schemasname,@tablename,@colname End Close cur1 --关闭游标 Deallocate cur1 --释放游标
sqlserver 全库查询 带架构
标签:架构 put schema status next -- 数据 class use