在数据库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

SQLServer 查询view中是否包含某个关键字的更多相关文章

  1. C#中查询字符串中是否包含指定字符/串,使用IndexOf还是Contains?

    C#中查询字符串中是否包含指定字符/串,使用IndexOf还是Contains?这是一个很常见的命题,以前也没有注意,今天QQ群里有人提起,于是就做了下试验,代码如下: using System; u ...

  2. IE11的变化 navigator.userAgent中不再包含“MSIE”关键字

    IE升级了,让人好头疼,升级个东西,我们也要跟着升级,程序猿压力大呀.... 1.navigator.userAgent中不再包含“MSIE”关键字 2.用javascript的判断是否是IE11的方 ...

  3. SQLSERVER | 查询数据库中所有的表的名字 | 查询数据库中的所有数据库名

    SQLSERVER 1.查询某个数据库中所有的表名:  SELECT Name FROM SysObjects Where XType='U' ORDER BY Name 2.查询数据库中的所有数据库 ...

  4. sqlserver查询数据库中包含某个字段的所有表和所有存储过程

    1.查询包含某字段的所有表 select object_name(id) objName,Name as colName from syscolumns where (name like'%你要查询的 ...

  5. SQLserver查询库中包含某个字段的表

    select [name] from [TPMS_PRD].[dbo].sysobjects where id in(select id from [TPMS_PRD].[dbo].syscolumn ...

  6. SqlServer查询存储过程中包含指定的内容

    存储过程太多,有时只记得存储过程里面的某一点类容,想要找到对应的存储过程: SELECT obj.Name 存储过程名, sc.TEXT 存储过程内容 FROM syscomments sc INNE ...

  7. 筛选出sql 查询结果中 不包含某个字符

    select * from table1 where patindex('%关键字%' , aa) = 0 select * from table1 where charindex('关键字' , a ...

  8. SQLSERVER 查询系统中的所有表的数量

    SELECT a.name, b.rows FROM sysobjects AS a INNER JOIN sysindexes AS b ON a.id = b.id WHERE (a.type = ...

  9. SqlServer查询Excel中的数据

    步骤如下: --1.开启远程查询支持 reconfigure reconfigure --2.链接Excel Microsoft ACE 12.0 OLE DB Provider 读Excel数据(注 ...

随机推荐

  1. pandas 筛选某一列最大值最小值 sort_values、groupby、max、min

    高效方法: dfs[dfs['delta'].isnull()==False].sort_values(by='delta', ascending=True).groupby('Call_Number ...

  2. Alpha冲刺(3/4)

    队名:福大帮 组长博客链接:https://www.cnblogs.com/mhq-mhq/p/11899921.html 作业博客 :https://edu.cnblogs.com/campus/f ...

  3. Cesium的Property机制总结

    前言 Cesium官方教程中有一篇叫<空间数据可视化>(Visualizing Spatial Data).该文文末简单提到了Cesium的Property机制,然后话锋一转,宣告此教程的 ...

  4. linux日常---3、linux常用操作

    linux日常---3.linux常用操作 一.总结 一句话总结: 状态的确是非常之好,享受这种状态. 1.linux删除文件夹和文件? rm -rf *:删文件和文件夹 rm -rf *.*:只能删 ...

  5. KA,连接池居然这么简单? 原创: 58沈剑 架构师之路 3月20日

    KA,连接池居然这么简单? 原创: 58沈剑 架构师之路 3月20日

  6. Celery如何修复Python的GIL问题

    小结: 1. Celery如何修复Python的GIL问题https://python.freelycode.com/contribution/detail/346 最近,我重读了Glyph写的Uny ...

  7. mac下如何安装python3?

    1. 安装homebrew $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/insta ...

  8. Android:修改连接到AP端显示的设备名

    一.Android系统代码中实现设备名分配 1. \frameworks\base\services\core\java\com\android\server\ConnectivityService. ...

  9. angular 中父子路由

    1. 创建组件引入组件 import { NewsaddComponent } from './components/newsadd/newsadd.component'; import { News ...

  10. 扯扯python的多线程的同步锁 Lock RLock Semaphore Event Condition

    我想大家都知道python的gil限制,记得刚玩python那会,知道了有pypy和Cpython这样的解释器,当时听说是很猛,也就意味肯定是突破了gil的限制,最后经过多方面测试才知道,还是那德行… ...