Rohit Bhagwani

Rohit Bhagwani

  • 1.1k
  • 617
  • 3.1k

Query to get database references in original defined format

Jan 2 2024 12:13 PM

Hello,  
We have an On-Premise database that we want to migrate to Azure via DMA, this database contains multiple objects which are dependent on objects from another database in the same server. We are trying to identify such dependencies.  

Example of few of the references are as below:  

databasename.schemaname.objectname
databasename.[schemaname].[objectname]  

Is there a T-SQL query which can help us get the object references in the original format?  (Edited)

For eg : A view has below SELECT Query :

SELECT * From db1.ABC.table1 AS t1
LEFT JOIN db2.[ABC].table2 AS t2 ON t1.Col1 = t2.Col2
LEFT JOIN db1.[ABC].[table1] AS t3 ON t2.Col1 = t3.Col

Here the objects are defined in different valid ways, I want to get the distinct values for the references (as shown below) in their actual defined way, can this be done via t-sql query ?

db1.ABC.table1
db2.[ABC].table2
db1.[ABC].[table1]

Thanks for the help in advance.


Answers (4)