zoukankan      html  css  js  c++  java
  • SQLServer 查询view中是否包含某个关键字

    在数据库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
    
  • 相关阅读:
    Java HashMap HashCode
    JS 笔记---持续更新
    彻底弄懂 JavaScript 执行机制
    几条jQuery代码片段助力Web开发效率提升
    原生JS与jQuery操作DOM对比
    jQuery->JavaScript一览表
    Jquery介绍
    canvas雪花
    canvas绘制多边形
    兼容性的事件处理程序
  • 原文地址:https://www.cnblogs.com/grj1046/p/FindFromViewContent.html
Copyright © 2011-2022 走看看