Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Management Studio 'View Dependencies' Not Listing All Dependencies

Tags:

sql

tsql

ssms

In the past I thought when right-clicking on a table in SSMS and click 'View Dependencies' it will list out all tables and stored procs that uses the table. But recently I noticed it miss some dependencies.

Sometimes it misses some stored procs that reference it using SELECT statements, sometimes it's INSERT or UPDATE statements. There doesn't seem to be a common pattern on what is dependent and what is not. Can any one shed some light on this? (And no, it's not a permission issue. I have sysadmin rights.)

My final goal is to find a way to find all dependencies on a particular table/view/stored proc using the simplest way (ie. little or no scripting) but it must return ALL dependencies, not just some. Any help?

PS. I'm using SQL Server 2005 and SSMS 2005.

Thanks.

like image 883
SF Lee Avatar asked Apr 02 '12 00:04

SF Lee


People also ask

How do I check dependencies in SSMS?

Using SQL Server Management Studio In Object Explorer, expand Databases, expand a database, and then expand Tables. Right-click a table, and then click View Dependencies.

How can I find all foreign key references to a table in SQL Server?

Using SQL Server Management Studio Open the Table Designer for the table containing the foreign key you want to view, right-click in the Table Designer, and choose Relationships from the shortcut menu. In the Foreign Key Relationships dialog box, select the relationship with properties you want to view.

How do I remove a dependencies from a table in SQL?

Right-click a database in SQL Server Object Explorer, and select Delete. Accept all the default settings in the Delete Database dialog, and click OK.


1 Answers

This is "known" problem with SQL server. And actually this SSMS feature is dangerous to use, particularly when you want to find out which objects do you have to change, if you have done some changes to a Table or View.

Also - do not use scripts to search in syscomments, as far as if object text is more that 8000 symbols it will be split into several parts, so that name of your table can be cut into

record1: ...... table_that_yo

record2: u_search ........

Previously my "recipe" was to script all object into text files to disk and perform "search in files" using any text editor - like in SSMS of notepad++ (Find in Files) function.

I have now created a script that allows searching in object definitions using built-in SQL functions:

/*
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]
like image 130
Andrei Rantsevich Avatar answered Oct 06 '22 17:10

Andrei Rantsevich