当前位置: 移动技术网 > IT编程>数据库>MSSQL > SQLServer 查询view中是否包含某个关键字

SQLServer 查询view中是否包含某个关键字

2019年08月28日  | 移动技术网IT编程  | 我要评论

府谷县政府网,古装美女换装小游戏,书包网 h

在数据库view的创建中,会遇到一些跨数据库的view脚本,但是在将view更新到production的时候可能忘记更改database name,导致出现一些问题。
以下脚本可以检查出包含某个关键字的view name,只需要修改where objecttext like '%word%'条件即可

--type(v,fn,p)
select name,row_number()over(order by name) as number into #tempobjects from sys.objects where type='v'
--
declare @rowindex int
declare @rowcount int
--
select @rowcount=count(*) from #tempobjects
set @rowindex=1
--
create table #tempfindobjecttext(objecttext varchar(max))
create table #tempfindobject(objectname varchar(500))
--
declare @objectname varchar(500)
--
while @rowindex<=@rowcount
begin
   select @objectname=name from #tempobjects where number=@rowindex
   --
   truncate table #tempfindobjecttext
   --
   insert into #tempfindobjecttext(objecttext)
   execute sp_helptext @objectname
   --
   if exists(select top 1 * from #tempfindobjecttext where objecttext like '%word%')
   begin
      insert into #tempfindobject(objectname)values(@objectname)
   end
   --
   set @rowindex=@rowindex+1
end
--
select * from #tempfindobject
--
truncate table #tempobjects
truncate table #tempfindobjecttext
truncate table #tempfindobject
--
drop table #tempobjects
drop table #tempfindobjecttext
drop table #tempfindobject

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网