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.
Rohit BhagwaniPosted Jan 4, 2024, 9:03 AM
Thankyou Nadnan, Namish, Jayraj for your repsonse.
Just to add, We have extracted the code from the database in visual studio, where we want to identify all the references (in the original format) in order to replace them with new objects.
So the desired output would be as below :
db1.ABC.table1
db2.[ABC].table2
db1.[ABC].[table1]
Nandan HegdePosted Jan 2, 2024, 2:13 PM
A slight correction to the query shared by Jayraj :
Naimish MakwanaPosted Jan 2, 2024, 12:30 PM
You can try below query.
Thanks
Jayraj ChhayaPosted Jan 2, 2024, 12:24 PM
To retrieve the object references in their original format, you can use the following T-SQL query:
In this query, you need to replace 'YourDatabaseName' with the name of your database and 'YourEntityName' with the name of the entity you want to retrieve the object references for.
The
sys.sql_expression_dependenciessystem view contains information about the dependencies between database objects. By joining this view with the necessary columns and using theDISTINCTkeyword, you can retrieve the distinct object references in their original format.For example, if you want to retrieve the object references for a view named 'YourViewName' in the 'YourDatabaseName' database, you would modify the query as follows:
This query will return the distinct object references in their original format, such as 'db1.ABC.table1', 'db2.[ABC].table2', and 'db1.[ABC].[table1]'.