# Virtual Relationship

Virtual relationships are used to link related entities based on a common attribute which helps in querying data and generating useful insights.

Consider entities that do not have relationships between them in the database. To derive insights from entities, we may need certain relationships in the data model while ensuring that the schema of the database remains the same.

To solve this problem, Astera Data Stack offers virtual relationships that help us create relationships between entities and leverage the benefits of relationships without forward engineering them to the database. Virtual relationships have similar characteristics as physical relationships, but they are not present in the database.

### Use Case

Consider an example where *Customers* and *Orders* tables are present in a database but are not connected with each other.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FUYYmLwy1AsqslVm2d9Ph%2Fimage-20230601224220125.png?alt=media\&token=e0007cc9-965c-4a10-aea3-07be3b526e7f)

A virtual relationship could be created between the entities using a common attribute such as the C*ustomerID*. Virtual relationships between two entities can be marked as virtual using any of the following steps

1. Right-click the relationship and select *Virtual* from the context menu.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2Fe7io3b7Vy2WV2AnoYa45%2Fimage-20230601224252275.png?alt=media\&token=a0a0e593-4b9a-4458-8970-2fca87d6ca6d)

2. Double-click the relationship to open the *Edit Relationship window and* mark the *Virtual* checkbox. Click *OK* to save the changes and close the window.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FsZwTceG0dDc3t17fRQ8t%2Fimage-20230601224319813.png?alt=media\&token=6b00f792-7323-41f6-80b5-253f4aadd824)

3. Open the *Relationship* *Manager* window either from the toolbar or using the short cut key, *Ctrl + Shift+ E.*

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2Fzj7uymOoVqBPuOMRlYhw%2Fimage-20230601224341790.png?alt=media\&token=21d4e919-5e49-4217-bf65-b71ae12e8c02)

4. Now, select the relationship and mark the *Virtual* checkbox. Click *OK* to close the window.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F03FhDrkDbiep7olfhUWU%2Fimage-20230601224354138.png?alt=media\&token=15b7ad1a-f6c7-436c-bd3f-d09ac4e1ad7d)

A virtual relationship between the *Customers* and *Orders* entities has been created successfully. This virtual relationship will not show any changes when applying diff nor will it give any verification errors when verifying for *Read and Write Deployment*.

<figure><img src="https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FTrcuMXL5jgpRgFuAlfX9%2Fimage.png?alt=media&#x26;token=105b3654-e54e-4e84-9439-aa55d1f2dc87" alt=""><figcaption></figcaption></figure>

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FbCxxkadECKahuoEvnKEr%2Fimage-20230601224447127.png?alt=media\&token=238942e8-636f-4ddc-a358-70e2aabd57da)
