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
    
  • 相关阅读:
    POJ3040--Allowance(贪心)
    Deep work
    湾区公司上班第一周
    三个现场面试
    协商薪资
    调节情绪,精神愉悦,健康快乐
    Phone interview guide 多说
    Campus Bikes
    降低软件复杂度 和 写注释写总结 2019-10
    某厂在线测试 2019.09.26
  • 原文地址:https://www.cnblogs.com/grj1046/p/FindFromViewContent.html
Copyright © 2011-2022 走看看