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
SQLServer 查询view中是否包含某个关键字的更多相关文章
- C#中查询字符串中是否包含指定字符/串,使用IndexOf还是Contains?
C#中查询字符串中是否包含指定字符/串,使用IndexOf还是Contains?这是一个很常见的命题,以前也没有注意,今天QQ群里有人提起,于是就做了下试验,代码如下: using System; u ...
- IE11的变化 navigator.userAgent中不再包含“MSIE”关键字
IE升级了,让人好头疼,升级个东西,我们也要跟着升级,程序猿压力大呀.... 1.navigator.userAgent中不再包含“MSIE”关键字 2.用javascript的判断是否是IE11的方 ...
- SQLSERVER | 查询数据库中所有的表的名字 | 查询数据库中的所有数据库名
SQLSERVER 1.查询某个数据库中所有的表名: SELECT Name FROM SysObjects Where XType='U' ORDER BY Name 2.查询数据库中的所有数据库 ...
- sqlserver查询数据库中包含某个字段的所有表和所有存储过程
1.查询包含某字段的所有表 select object_name(id) objName,Name as colName from syscolumns where (name like'%你要查询的 ...
- SQLserver查询库中包含某个字段的表
select [name] from [TPMS_PRD].[dbo].sysobjects where id in(select id from [TPMS_PRD].[dbo].syscolumn ...
- SqlServer查询存储过程中包含指定的内容
存储过程太多,有时只记得存储过程里面的某一点类容,想要找到对应的存储过程: SELECT obj.Name 存储过程名, sc.TEXT 存储过程内容 FROM syscomments sc INNE ...
- 筛选出sql 查询结果中 不包含某个字符
select * from table1 where patindex('%关键字%' , aa) = 0 select * from table1 where charindex('关键字' , a ...
- SQLSERVER 查询系统中的所有表的数量
SELECT a.name, b.rows FROM sysobjects AS a INNER JOIN sysindexes AS b ON a.id = b.id WHERE (a.type = ...
- SqlServer查询Excel中的数据
步骤如下: --1.开启远程查询支持 reconfigure reconfigure --2.链接Excel Microsoft ACE 12.0 OLE DB Provider 读Excel数据(注 ...
随机推荐
- 设计一个树型目录结构的文件系统,其根目录为 root,各分支可以是目录,也可以是文件,最后的叶子都是文件。
设计一个树型目录结构的文件系统,其根目录为 root,各分支可以是目录,也可以是文件,最后的叶子都是文件. 我实现的功能是提供父目录(兄弟目录),输入文件名,创建树型目录结构,文本文件不可以再有子目录 ...
- luogu4208
P4208 [JSOI2008]最小生成树计数 题目描述 现在给出了一个简单无向加权图.你不满足于求出这个图的最小生成树,而希望知道这个图中有多少个不同的最小生成树.(如果两颗最小生成树中至少有一条边 ...
- Unrecognized syntax identifier "proto3". This parser only recognizes "proto2". ”问题解决方法
编译cartographer时遇到Unrecognized syntax identifier “proto3”. This parser only recognizes “proto2”.排查:使用 ...
- Synchronized 原理
1.同步代码块: 反编译结果: monitorenter : 每个对象有一个监视器锁(monitor).当monitor被占用时就会处于锁定状态,线程执行monitorenter指令时尝试获取moni ...
- ICEM-叶轮泵腔(2D转3D)
原视频下载地址:https://yunpan.cn/cqUfdgMPzyr5y 访问密码 bb4f
- webapi接口上传大文件
通过WebApi或者MVC模式的接口上传文件时,总数报错 413 Request Entity Too Large IIS 404 服务未找到 解决方法: 1. 在web.config文件下找到sys ...
- 2018-2019-2 20165312《网络对抗技术》Exp9 Web安全基础
2018-2019-2 20165312<网络对抗技术>Exp9 Web安全基础 目录 Exp9_1安装Webgoat Exp9_2 SQL注入攻击 Numeric SQL Injecti ...
- postgresql 计算时间差的秒数、天数
处理时间时用到了,记录一下. 计算时间差天数 select extract(day FROM (age('2017-12-10'::date , '2017-12-01'::date))); 计算时间 ...
- arcgis python 新生成的数据设置
try: # Update the spatial index(es) # r = arcpy.CalculateDefaultGridIndex_management(outFeatures) ar ...
- sql data compare
https://documentation.red-gate.com/sdc14 About SQL Data Compare With SQL Data Compare, you can compa ...