I have a system with several databases and client applications. All databases are in the same instance of SQL Server. They were developed by different people at different times. Therefore, if some error occurs, it is difficult to find in which procedure or to initiate a data change.
Now I use this script that 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') AND obj.type_desc='USER_TABLE' ORDER BY TableName,Ref_Object,Ref_Object_Name
But this script only works for the database to which the table belongs.
I want to get a list of object names (or even better for an object) for all objects of all databases in which the specified table name occurs:
Database_Name SchemaName ObjectName ObjectKind
Thanks.
source share