这是 SQL 服务器的“已知”问题。实际上,这个 SSMS 功能使用起来很危险,尤其是当您想找出必须更改哪些对象时,如果您对表或视图进行了一些更改。
另外 - 不要使用脚本在 syscmets 中搜索,如果对象文本超过 8000 个符号,它将被分成几个部分,以便您的表格名称可以被切割成
record1: ...... table_that_yo
record2: u_search ........
以前我的“食谱”是将所有对象编写成文本文件到磁盘并使用任何文本编辑器执行“在文件中搜索” - 就像在记事本++(在文件中查找)功能的 SSMS 中一样。
我现在创建了一个允许使用内置 SQL 函数在对象定义中搜索的脚本:
/*
This is an easy way to look through the sources of all objects in the database
if you need to find particular string. This script can be used, for example,
to find references of some specific object by other objects. Depending on the
size of your database you might want to limit the search scope to particular
object type. Just comment unneeded object types in WHERE statement.
Enter search string between %% marks in @SearchPattern initialisation statement.
When you get the results you can copy object name from "FullName" column and
use SSMSBoost to quickly locate it in the object explorer, or you can continue
searching in results using "Find in ResultsGrid" function.
This script is provided to you by SSMSBoost add-in team as is. Improvements and
comments are welcome.
Redistribution with reference to SSMSBoost project website is welcome.
SSMSBoost team, 2014
*/
DECLARE @SearchPattern NVARCHAR(128)
SET @SearchPattern = '%%'
SELECT SCHEMA_NAME(o.schema_id) as [schema]
, o.[name]
, o.[type]
, '['+SCHEMA_NAME(o.schema_id)+'].['+o.[name]+']' as FullName
, OBJECT_DEFINITION(object_id) AS [Source]
FROM sys.objects AS o
WHERE lower(OBJECT_DEFINITION(o.object_id)) LIKE lower(@SearchPattern)
AND o.[type] IN (
'C',--- = Check constraint
'D',--- = Default (constraint or stand-alone)
'P',--- = SQL stored procedure
'FN',--- = SQL scalar function
'R',--- = Rule
'RF',--- = Replication filter procedure
'TR',--- = SQL trigger (schema-scoped DML trigger, or DDL trigger at either the database or server scope)
'IF',--- = SQL inline table-valued function
'TF',--- = SQL table-valued function
'V') --- = View
ORDER BY o.[type]
, o.[name]