How to refer objects from another database?


I have a MSSQL database to deploy some changes to but I need to refer objects from another MSSQL database. I have been deploying DB changes with SSDT and refer objects from another DB i.e., “db123” as shown below and use dacpacs.

CREATE VIEW [dbo].[vSurvey_1]

SELECT a.clinic_id, Vote_ScoreAsText = a.Vote, Vote_DateTime = a.DateTime, a.DType FROM
, rps.Vote
, pps.DType
, rps.DateTime
/*, Testing rps_id =, pps_id = */
, rank = rank() OVER (partition BY rps.ID ORDER BY pps.Created desc)
FROM Results_Survey rps WITH (nolock)
INNER JOIN Process_Survey pps WITH (nolock)
ON pps.PhoneNumber = rps.MobileNumber
AND [$(db123)].dbo.TrimTime(pps.Created) <= [$(db123)].dbo.TrimTime(rps.DateTime)

) a
WHERE a.rank = 1

As we refer objects from the “db123” database in the above view while deploying changes using SSDT, do we have an option to do the same with Liquibase or some work around to refer objects from “db123” in our current database and avoid data duplication?

Please let me know! Thank You!!!

Hi @sr.kancham
While I am not sure what SSDT means and what is used for, with regard to how to use dynamically passed values to a changelog/changeset, here is something that could help:

Also, on the same topic, asked here:

So in few words, you would need to have the changelog/changeset contain the pattern ${databaseName} where needed, as a token (in your example, preceeding the dbo schema) and this token’s value can be set, as a parameter/value at runtime in the liquibase command: liquibase ... -DdatabaseName=<actual name>

Hope this helps,