Microsoft has exposed the scriptdom API to parse and generate TSQL. I\'m new to it and still playing with it. I want to know how to get the cross databases references from q
Perhaps another way to attempt this is to execute your query as:
SET SHOWPLAN_XML ON;
UPDATE t3
SET description = 'abc'
FROM database1.dbo.table1 t1
INNER JOIN database2.dbo.table2 t2
ON (t1.id = t2.t1_id)
LEFT OUTER JOIN database3.dbo.table3 t3
ON (t3.id = t2.t3_id)
INNER JOIN database2.dbo.table4 t4
ON (t4.id = t2.t4_id)
This returns an XML query plan. In the XML you will find the join conditions under a RelOp node. For example for a hash join loop you will see something like:
.. some stuff cut from here
..
For a nested loop something along the lines of:
Perhaps you could then process this in C# to extract all joins then compare the databases held in the column references.
Apologies for the formatting.