Mapping the Unknown: Using DBeaver Virtual Relationships for Legacy Databases
Stop guessing how legacy tables relate. Learn how to use DBeaver's Virtual Foreign Keys to map undocumented databases and generate ER diagrams without modifying production schemas.
18 Aug 2025, 14:39 UTC

The Legacy Schema Nightmare
You inherit a production database from 2008. There are 150 tables, no documentation, and—worst of all—zero formal foreign key constraints. The original developers relied on application-level logic to maintain referential integrity, leaving you to guess which user_id in the orders table actually maps to the id in the accounts table.
The immediate instinct is to run ALTER TABLE commands to add constraints and make the schema discoverable. However, in a production environment, adding constraints to millions of rows can lock tables for hours or fail entirely due to existing orphaned data. The goal is to visualize and navigate the data without touching the physical schema.
Client-Side Metadata with Virtual Keys
DBeaver provides a feature called Virtual Foreign Keys. Unlike standard foreign keys, these are stored in your local DBeaver project workspace rather than the database server. They act as a metadata overlay, telling the IDE how tables relate without risking a production outage or requiring DBA permissions to modify the schema.
When you define a virtual relationship, DBeaver treats that link as if it were a real constraint for the purpose of UI navigation and visualization. This allows you to use the Navigate to Related Table feature, letting you jump from a record in a child table directly to its corresponding parent record via a single click.
Visualizing the Invisible ERD
The most immediate benefit of virtual keys is the impact on the Entity Relationship Diagram (ERD) tool. Normally, a database without constraints results in a collection of floating boxes in the ERD view. By adding virtual keys, you manually "wire" the diagram.
This transforms the ERD from a list of tables into a functional map. Because these mappings are stored locally, you can experiment with different relationship hypotheses—such as whether a relationship is one-to-one or one-to-many—without affecting other users or the data itself.
Worked Example: Mapping a Legacy Order System
Assume you have two tables: legacy_orders and customer_master. There is no formal link, but you know legacy_orders.cust_ref maps to customer_master.cid.
- Open Table Properties: In the Database Navigator, right-click the
legacy_orderstable and select View Diagram or open the Properties tab. - Define the Link: Navigate to the Virtual Foreign Keys section. Click the Add button.
- Configure Mapping:
- Target Table: Select
customer_master. - Column Mapping: Map
cust_ref(Source) tocid(Target).
- Target Table: Select
- Verify: Open the ER Diagram for both tables. A connecting line will now appear. In the Data Editor for
legacy_orders, you can now click the link icon next to acust_refvalue to jump directly to the matching row incustomer_master.
The Trade-offs of Virtual Metadata
Virtual keys are a productivity tool, not a database management strategy. There are three primary limitations to keep in mind:
- No Enforcement: Virtual keys do not prevent orphaned records. If you delete a parent row, the child row remains, as the database engine is unaware of the virtual link.
- Local Scope: These definitions exist only in your DBeaver project. If a teammate needs the same mappings, you must export the project settings or share the project folder via Git; they will not see the links simply by connecting to the same database.
- Performance: In schemas with thousands of tables and hundreds of virtual mappings, the local metadata cache can slow down the initial loading of the ERD tool.
Practical Verification
To ensure your virtual mappings are working correctly, perform a Cross-Table Jump: Open the data grid for your child table, locate a value in the virtual foreign key column, and use the navigation shortcut (typically clicking the link icon or using the context menu). If DBeaver opens the parent table and highlights the specific corresponding row, the mapping is functionally correct.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.