Does any know how / if it is possible to view all tables/views/stored procedures that depend on a linked server in Sql Server 2008. Basically as if the context menu "View dependencies" was accessible for linked servers?
Any help much appreciated.
Thanks
Using SQL Server Management StudioIn Object Explorer, expand Databases, expand a database, and then expand Tables. Right-click a table, and then click View Dependencies.
Open SQL Server Management Studio; go to Server Objects -> Linked Server. Under Linked Server node we have Providers node that already having installed provides and that mapped to SQL Server.
To filter, search for the value in the c1.name or c2.name column. To look for all the references to a certain column, use the c2.name for the column name and the OBJECT_NAME(k. referenced_object_id) as the table which holds the c2 column :) Good Luck!
Search for it
SELECT OBJECT_NAME(object_id), *
FROM sys.sql_modules
WHERE definition LIKE '%myLinkedServer%'
Or use the free Red gate SQL Search to do the same with a GUI
There is no table or feature that tracks dependencies between the server-level linked server objects and database-level objects
Note: INFORMATION_SCHEMA views and the legacy syscomments truncate the definition so are unreliable for definition searches.
Following @Mitch Wheat's suggestion, here's some sql to run @gbn's answer for all db's on the server. Maybe this will a bit of time for someone.
USE Master;
GO
IF OBJECT_ID('tempdb..#Deps') IS NOT NULL
BEGIN
DROP TABLE #Deps
END
CREATE TABLE #Deps
(
[ServerName] [VARCHAR](500) NOT NULL,
[DatabaseName] [VARCHAR](500) NOT NULL,
[SchemaName] [VARCHAR](500) NOT NULL,
[ObjectName] [VARCHAR](MAX) NULL,
[ObjectId] [INT] NOT NULL,
[ObjectType] [VARCHAR](500) NOT NULL,
[DependsOnLinkedServer] [VARCHAR](500) NOT NULL,
[definition] [VARCHAR](MAX) NULL
)
IF OBJECT_ID('tempdb..#Queries') IS NOT NULL
BEGIN
DROP TABLE #Queries
END
SELECT
REPLACE('INSERT INTO #Deps
(
[ServerName]
,[DatabaseName]
,[SchemaName]
,[ObjectName]
,[ObjectType]
,[ObjectId]
,[DependsOnLinkedServer]
,[definition]
)
SELECT
@@SERVERNAME,
''?'' AS DatabaseName,
s.name AS SchemaName,
o.name AS ObjectName,
o.type_desc AS ObjectType,
m.object_id AS ObjectId,
''' + srv.name + ''' AS DependsOnLinkedServer,
m.definition
FROM
[?].sys.sql_modules m
LEFT OUTER JOIN [?].sys.objects o
ON m.object_id = o.object_id
LEFT OUTER JOIN [?].sys.schemas s
ON o.schema_id = s.schema_id
WHERE
definition LIKE ''%' + srv.name + '%''', CHAR(13) + CHAR(10), '') AS Query
INTO
#Queries
FROM
sys.servers srv;
GO
DECLARE @Query AS VARCHAR(MAX)
DECLARE LinkedServerCursor CURSOR FAST_FORWARD
FOR
SELECT
Query
FROM
#Queries
OPEN LinkedServerCursor
FETCH NEXT FROM LinkedServerCursor INTO @Query;
WHILE @@FETCH_STATUS = 0
BEGIN
EXECUTE master.sys.sp_MSforeachdb @Query
FETCH NEXT FROM LinkedServerCursor INTO @Query;
END
CLOSE LinkedServerCursor;
DEALLOCATE LinkedServerCursor;
GO
SELECT
ServerName,
DatabaseName,
ObjectName,
'[' + ServerName + '].[' + DatabaseName + '].[' + SchemaName + '].[' + ObjectName + ']' AS QualifiedObjectName,
DependsOnLinkedServer,
ObjectType
FROM
#Deps
ORDER BY
ServerName,
DatabaseName,
ObjectName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With