Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6380061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:13:07+00:00 2026-05-25T02:13:07+00:00

I have a system with multiple databases and client applications. All databases are at

  • 0

I have a system with multiple databases and client applications. All databases are at one SQL Server instance. They have been developed by different people at different time. So if some error occur it is pritty hard to find in which procedure or trigger the data was modified.

Now I use this script, which I found on this site:

SELECT  DISTINCT ISNULL(sd.referenced_schema_name+'.','')+ OBJECT_NAME(sd.referenced_id)TableName,
        OBJECT_NAME(sd.referencing_id)Ref_Object,
        CASE WHEN OBJECTPROPERTYEX(sd.referencing_id,N'IsUserTable')= 1
                     THEN'Table'
        WHEN OBJECTPROPERTYEX(sd.referencing_id,N'IsTableFunction')= 1
                     THEN'Function'
        WHEN OBJECTPROPERTYEX(sd.referencing_id,N'IsTableFunction')= 1
                     THEN'Function'
        WHEN OBJECTPROPERTYEX(sd.referencing_id,N'IsScalarFunction')=1
                     THEN'Function'
        WHEN OBJECTPROPERTYEX(sd.referencing_id,N'IsTrigger')= 1
                     THEN'Trigger'
        WHEN OBJECTPROPERTYEX(sd.referencing_id,N'IsView')= 1
                     THEN'View'
        WHEN OBJECTPROPERTYEX(sd.referencing_id,N'IsUserTable')= 1
                     THEN'Table'
        WHEN OBJECTPROPERTYEX(sd.referencing_id,N'IsProcedure')= 1
                     THEN'Procedure'
        WHEN OBJECTPROPERTYEX(sd.referencing_id,N'IsIndexed')= 1
                     THEN'Index'
        WHEN OBJECTPROPERTYEX(sd.referencing_id,N'IsForeignKey')= 1
                     THEN'ForeignKey'
        WHEN OBJECTPROPERTYEX(sd.referencing_id,N'IsPrimaryKey')= 1
                     THEN'PrimaryKey'
        END AS Ref_Object_Name
FROM    sys.sql_expression_dependencies SD
        INNER JOIN sys.objects obj
                     ON obj.object_id=sd.referenced_id
WHERE   obj.is_ms_shipped= 0
        and referenced_id=object_id('TABLE_NAME') /*Where one can Replace table Name*/
        AND obj.type_desc='USER_TABLE'
        ORDER BY TableName,Ref_Object,Ref_Object_Name

But this script seems to work only for the database to which the table belong.

I want to get for a specified table name (or even better for an object) list of all objects of all databases in which the specified table name met:

Database_Name  SchemaName  ObjectName  ObjectKind  

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:13:07+00:00Added an answer on May 25, 2026 at 2:13 am
    DECLARE @table_name SYSNAME = N'%';
    
    
    
    DECLARE @sql NVARCHAR(MAX) = N'';
    
    SELECT @sql += 'SELECT DISTINCT Database_Name = ''' + QUOTENAME(name) + ''',
            COALESCE(sd.referenced_schema_name +''.'', '''')+ o.name AS TableName,
            r.name AS Ref_Object,
            r.type_desc AS Ref_Object_Name
    FROM    ' + QUOTENAME(name) + '.sys.sql_expression_dependencies AS sd
            INNER JOIN ' + QUOTENAME(name) + '.sys.objects AS o
            ON o.object_id = sd.referenced_id
            INNER JOIN ' + QUOTENAME(name) + '.sys.objects AS r
            ON sd.referencing_id = r.object_id
    WHERE   o.is_ms_shipped =  0
            and referenced_id = o.object_id
            AND o.type_desc = ''USER_TABLE''
            AND o.name LIKE ''' + @table_name + '''
    UNION ALL
    '
     FROM sys.databases 
     WHERE database_id BETWEEN 5 AND 32766;
    
    SET @sql = LEFT(@sql, LEN(@sql)-11) 
        + 'ORDER BY Database_Name, TableName,Ref_Object,Ref_Object_Name';
    
    EXEC sp_executesql @sql;
    

    EDIT

    The above will find all the references within each database, but won’t find cross-database references. It took a little playing, and the output isn’t precisely what you wanted, but I think it makes it more self-explanatory:

    DECLARE @table_name SYSNAME = N'%'; -- find all
    
    
    
    CREATE TABLE #d
    (
        db SYSNAME, 
        [object_id] INT, 
        sch SYSNAME,
        obj SYSNAME,
        ref_db NVARCHAR(128),
        ref_sch NVARCHAR(128), 
        ref_obj NVARCHAR(128),
        ref_object_id INT,
        type_desc SYSNAME
    );
    
    DECLARE @sql NVARCHAR(MAX) = N'';
    
    SELECT @sql += 'SELECT ''' + QUOTENAME(name) + ''',
        d.referencing_id,
        QUOTENAME(s.name),
        QUOTENAME(o.name),
        QUOTENAME(d.referenced_database_name),
        QUOTENAME(d.referenced_schema_name),
        QUOTENAME(d.referenced_entity_name),
        d.referenced_id,
        o.type_desc
    FROM ' + QUOTENAME(name) 
        + '.sys.sql_expression_dependencies AS d
    INNER JOIN ' + QUOTENAME(name) 
        + '.sys.objects AS o
        ON d.referencing_id = o.[object_id]
    INNER JOIN ' 
        + QUOTENAME(name) + '.sys.schemas AS s
        ON o.[schema_id] = s.[schema_id]
    WHERE d.referenced_entity_name LIKE ''' + @table_name + '''
    UNION ALL
    '
    FROM sys.databases WHERE database_id BETWEEN 5 AND 32766;
    
    SET @sql = LEFT(@sql, LEN(@sql)-11);
    
    INSERT #d EXEC sp_executesql @sql;
    
    SELECT 
        db+'.'+sch+'.'+obj, 
        ' (' + type_desc + ') references => ',
        COALESCE(ref_db, db)+'.'+ref_sch+'.'+ref_obj
        FROM #d;
    GO
    
    DROP TABLE #d;
    GO
    

    Sample output:

    [db1].[dbo].[foo]  (SQL_STORED_PROCEDURE) references =>   [db2].[dbo].[bar]
    [db1].[dbo].[xyz]  (SQL_STORED_PROCEDURE) references =>   [db1].[dbo].[table_xyz]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed middleware that provides RPC functionality to multiple client applications on multiple
I have a system in which different server processes are handling requests passed as
I have a system where I query a REST / Atom server for documents.
I have a system which sits on a web server and generates files on
I have a software system that performs OCR on Multiple machine simultaneously. Current system
So, I have an app that uses a SQL Server express db. I have
I'm in the process of converting a system from sql server to mongodb. I
Summary : synchronisation of multiple SQLite databases with server side sequentially. I'm working on
I am working on a system with one master and multiple clients that communicate
I have a system that combines the best and worst of Java and PHP.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.