搜索sql server数据库中包含有某个关键字的存储过程
当我们进行数据库修改的时候,如果数据库结构发生变化,例如表名、字段名、引用的数据库名发生了变化,需要修改相应的存储过程里面的引用。这个时候用一条SQL语句来查找出所有包含该关键字的存储过程使得我们的操作更方便
方法一:
select OBJECT_NAME(id) as sp_name,id from syscomments where id in ( select object_id(name) from dbo.sysobjects where xtype='P' ) and text like '%UAM.dbo%' group by id order by sp_name
方法二:
SELECT Name FROM sys.procedures WHERE OBJECT_DEFINITION(object_id) LIKE '%PGSUAM.dbo%'
方法三:
SELECT OBJECT_NAME(object_id) FROM sys.sql_modules WHERE Definition LIKE '%UAM.dbo%' AND OBJECTPROPERTY(object_id, 'IsProcedure') = 1
方法四:
SELECT ROUTINE_NAME, ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_DEFINITION LIKE '%UAM.dbo%' AND ROUTINE_TYPE='PROCEDURE'