在过去,我想当右键单击SSMS中的表并单击"查看依赖项"时,它会列出使用该表的所有表和存储过程.但最近我注意到它错过了一些依赖.
有时它会错过一些使用SELECT语句引用它的存储过程,有时它是INSERT或UPDATE语句.在什么是依赖和什么不依赖的情况下似乎没有共同的模式.任何人都可以对此有所了解吗?(不,这不是权限问题.我有sysadmin权限.)
我的最终目标是找到一种方法,使用最简单的方法(即很少或没有脚本)找到特定表/视图/存储过程的所有依赖项,但它必须返回所有依赖项,而不仅仅是一些依赖项.有帮助吗?
PS.我正在使用SQL Server 2005和SSMS 2005.
谢谢.
And*_*ich 10
这是SQL服务器的"已知"问题.实际上,这个SSMS功能使用起来很危险,特别是当您想要找出哪些对象需要更改时,如果您对表或视图进行了一些更改.
另外 - 不要使用脚本在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]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4384 次 |
| 最近记录: |