這是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