这是SQL Server的“已知”问题。实际上,这个SSMS功能使用起来很危险,特别是当你想要找出你必须改变哪些对象时,如果你对Table或View做了一些改变。
而且 - 不使用脚本在syscomments中进行搜索,就好像对象文本是超过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]
[我知道这是2008年,但它有许多有用的信息](http://sqlblog.com/blogs/aaron_bertrand/archive/2008/09/09/keeping-sysdepends-up-to- date-in-sql-server-2008.aspx) – 2012-04-02 01:53:47