SQLServer 查询view中是否包含某个关键字
2024-09-01 14:31:47
在数据库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
最新文章
- Oracle碎碎念~2
- Java中值传递和引用传递的概念
- textarea光标处插入文字
- 20145211 《Java程序设计》第1周学习总结——小荷才露尖尖角
- Razor语法学习
- POJ 2763 Housewife Wind (树链剖分 有修改单边权)
- JDK+Tomcat+MyEclipse发布JSP项目——不能成功的问题
- django: db howto - 1
- 人脸对齐ASM-AAM-CLM的一些总结
- 自己主动机串标:Directed Acyclic Word Graph
- Linux文件
- percona-toolkit 之 【pt-online-schema-change】说明【转】
- centos设置网卡开机自启动
- 浅谈.net中数据库操作事务
- php框架中,try,catch不能用的问题(转载)
- css盒子模型之边框
- 【JS点滴】substring和substr以及slice和splice的用法和区别。
- Net Core 使用外部登陆提供程序登陆的流程,以及身份认证的流程
- Class.forName和ClassLoader.loadClass的比较【转载】
- wampserver下配置虚拟主机 实现多站点支持